All files / src/lib gen-id.js

77.78% Statements 7/9
50% Branches 2/4
100% Functions 1/1
77.78% Lines 7/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    1x 1x           1x 1x             1x     1x     1x    
// utility for generating a uid for each component file
// used in scoped CSS rewriting
const hash = require('hash-sum')
const cache = Object.create(null)
 
// module.exports = function genId (file) {
//   return cache[file] || (cache[file] = hash(file))
// }
 
module.exports = function genId(file, configs){
  Iif(cache[file.subpath]){
    return cache[file.subpath];
  }
 
  let scopeId;
 
  // scope replace
  Iif (configs.cssScopedType == 'sum') {
    scopeId = hash(file.subpath);
  } else {
    scopeId = fis.util.md5(file.subpath, configs.cssScopedHashLength);
  }
 
  return cache[file.subpath] = scopeId;
};