Code coverage report for css-imports/index.js

Statements: 100% (19 / 19)      Branches: 100% (6 / 6)      Functions: 100% (4 / 4)      Lines: 100% (17 / 17)      Ignored: none     

All files » css-imports/ » index.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    1   1 4 4 3 3 3   3 3 10             3     1 1 4     1     1 3    
'use strict';
 
module.exports = imports;
 
function imports(str, fn) {
  if (str instanceof Buffer) str = str.toString();
  if (fn) return map(str, fn);
  var re = /@import *(?:url\(['"]([^'"]+)['"]\)|['"]([^'"]+)['"]);?/g;
  var ret = [];
  var m;
 
  str = removeComment(str);
  while (m = re.exec(str)) {
    ret.push({
      string: m[0],
      path: m[1] || m[2],
      index: m.index
    });
  }
 
  return ret;
}
 
function map(str, fn) {
  imports(str).forEach(function(r){
    str = str.replace(r.string, fn(r));
  });
 
  return str;
}
 
function removeComment(str) {
  return str.replace(/\/\*[\S\s]*?\*\//g, '');
}