zhangnaisong
2023-08-05 24d66c8d82b628a06e93dbb1abfea2049b3d45ab
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
const { interpolateName, getHashDigest } = require('loader-utils');
 
/**
 * @param {PostHTMLTree} tree
 * @return {Object} Node
 */
exports.getRoot = function getRoot(tree) {
  return tree.find(node => typeof node === 'object' && 'tag' in node);
};
 
/**
 * @param {string|Function} pattern
 * @param {string} resourcePath
 * @param {Object} [options]
 * @param {string} options.context
 * @param {string} options.content
 * @param {string} options.regExp
 */
exports.interpolate = function interpolate(pattern, resourcePath, options = null) {
  const opts = Object.assign({ context: process.cwd() }, options);
 
  return interpolateName({ resourcePath }, pattern, opts);
};
 
exports.getHash = function getHash(content) {
  return getHashDigest(content, 'md5', 'hex', 6);
};