1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const { extname } = require('path');
|
9 |
|
10 |
|
11 | const _ = require('lodash');
|
12 |
|
13 | const merge = Object.assign.bind(Object, Object.create(null));
|
14 |
|
15 | function replaceExt(filename, extension) {
|
16 | return filename.slice(0, 0 - extname(filename).length) + extension;
|
17 | }
|
18 |
|
19 |
|
20 | class PrepCache {
|
21 | constructor(prepFn) {
|
22 | this.prepFn = prepFn;
|
23 | this.cache = Object.create(null);
|
24 | }
|
25 | get(id, ...rest) {
|
26 | if (!(id in this.cache)) this.cache[id] = this.prepFn(id, ...rest);
|
27 | return this.cache[id];
|
28 | }
|
29 | }
|
30 | module.exports = {
|
31 | PrepCache,
|
32 | replaceExt,
|
33 | merge
|
34 | };
|