UNPKG

773 BJavaScriptView Raw
1const { interpolateName, getHashDigest } = require('loader-utils');
2
3/**
4 * @param {PostHTMLTree} tree
5 * @return {Object} Node
6 */
7exports.getRoot = function getRoot(tree) {
8 return tree.find(node => typeof node === 'object' && 'tag' in node);
9};
10
11/**
12 * @param {string|Function} pattern
13 * @param {string} resourcePath
14 * @param {Object} [options]
15 * @param {string} options.context
16 * @param {string} options.content
17 * @param {string} options.regExp
18 */
19exports.interpolate = function interpolate(pattern, resourcePath, options = null) {
20 const opts = Object.assign({ context: process.cwd() }, options);
21
22 return interpolateName({ resourcePath }, pattern, opts);
23};
24
25exports.getHash = function getHash(content) {
26 return getHashDigest(content, 'md5', 'hex', 6);
27};