UNPKG

747 BJavaScriptView Raw
1// _ _ _
2// | | (_) |
3// _ _| |_ _| |___
4// | | | | __| | / __|
5// | |_| | |_| | \__ \
6// \__,_|\__|_|_|___/
7
8const { /* join, relative, resolve, */ extname } = require('path');
9// const { stat, readFile } = require('fs');
10
11const _ = require('lodash');
12
13const merge = Object.assign.bind(Object, Object.create(null));
14
15function replaceExt(filename, extension) {
16 return filename.slice(0, 0 - extname(filename).length) + extension;
17}
18
19
20class 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}
30module.exports = {
31 PrepCache,
32 replaceExt,
33 merge
34};