UNPKG

1.25 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _path = _interopRequireDefault(require("path"));
9
10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12function interpolateName(name, filename) {
13 const match = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(name);
14 const [, replacerFile] = match;
15 const replacerQuery = match[2] || '';
16 const replacerFragment = match[3] || '';
17
18 const replacerExt = _path.default.extname(replacerFile);
19
20 const replacerBase = _path.default.basename(replacerFile);
21
22 const replacerName = replacerBase.slice(0, replacerBase.length - replacerExt.length);
23 const replacerPath = replacerFile.slice(0, replacerFile.length - replacerBase.length);
24 const pathData = {
25 file: replacerFile,
26 query: replacerQuery,
27 fragment: replacerFragment,
28 path: replacerPath,
29 base: replacerBase,
30 name: replacerName,
31 ext: replacerExt || ''
32 };
33 let newName = filename;
34
35 if (typeof newName === 'function') {
36 newName = newName(pathData);
37 }
38
39 return newName.replace(/\[(file|query|fragment|path|base|name|ext)]/g, (p0, p1) => pathData[p1]);
40}
41
42var _default = interpolateName;
43exports.default = _default;
\No newline at end of file