Code coverage report for src/helper.js

Statements: 66.67% (12 / 18)      Branches: 75% (6 / 8)      Functions: 33.33% (3 / 9)      Lines: 70.59% (12 / 17)      Ignored: none     

All files » src/ » helper.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46      1 1   1 27     1           1               27     14 12 12 12   2                          
// vim: set shiftwidth=2 expandtab:
'use strict';
 
var util = require('util');
var cleancss = require('clean-css');
 
var isType = function(o, type) {
  return Object.prototype.toString.call(o) === '[object ' + type + ']';
}
 
var flatten = function(arr) {
  return arr.reduce(function(tot, cur) {
    return tot.concat(util.isArray(cur) ? flatten(cur) : cur);
  }, []);
};
 
module.exports = {
  mincss: function(css) { return cleancss.process(css); },
  minjs: require('uglify-js'),
  pluck: function(arr, prop) {
    return arr.map(function(item) { return item[prop]; });
  },
  flatten: flatten,
  inArray: function(arr, str) { return arr.indexOf(str) !== -1; },
  isString: function(obj) { return isType(obj, 'String'); },
 
  urlsRelative: function(css, path) {
    if (module.exports.isString(css) && module.exports.isString(path)) {
      path = path.indexOf('/', path.length -1) > -1? path : path + '/';
      var regex = /(url\(["']?)([^/'"][\w/.]*)/gm;
      return css.replace(regex, "$1" + path + "$2");
    } else {
      throw new Error('1st and 2nd args must be strings.');
    }
  },
 
  // Filetypes and matching preprocessor binaries.
  fileTypes: {
    '.css': null,
    '.sass': 'sass',
    '.scss': 'scss',
    '.less': 'lessc',
    '.styl': 'stylus'
  }
}