Code coverage report for css-imports/index.js

Statements: 100% (18 / 18)      Branches: 100% (6 / 6)      Functions: 100% (3 / 3)      Lines: 100% (16 / 16)      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    1   1   1 4 4 3 3 3   3 3 14             3     1 1 6     1    
'use strict';
 
var stripComments = require('strip-comments');
 
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 = stripComments.block(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;
}