-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal.js
54 lines (46 loc) · 1.03 KB
/
original.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Argvs {
// Constructor
constructor() {
// Save Argvs
this.cache = {};
// Prefix
this.exp = new RegExp(`^--`);
// Execute
return this;
}
pick(argvs = JSON.parse(process.env.npm_config_argv)) {
// Filter Argvs
return argvs.original
? argvs.original.filter(cmd => this.exp.test(cmd))
: {};
}
tolerant(argvs, quota = false) {
// Map Chance
argvs.map(
// Each
param => (
// Remove Prefix
(param = param.replace(this.exp, "")),
// Tolerant Param
param.replace(
// RegExp
/^([\w\.\-\:\/]+)\=?(.*)/g,
// Transfer
($0, $1, $2) => (
// in Cache with Quota
(this.cache[$1] = quota ? `"${$2 || true}"` : `${$2 || true}`), $0
)
)
)
);
return argvs;
}
get(name) {
// Argvs
const Argvs = this.tolerant(this.pick(), name === true);
// Result
return name ? this.cache[name] : this.cache;
}
}
// Export
module.exports = new Argvs();