forked from sindresorhus/configstore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (42 loc) · 780 Bytes
/
index.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
'use strict';
const dotProp = require('dot-prop');
class Configstore {
constructor(id, defaults, options = {}) {
this.all = {};
if (defaults) {
this.all = {
...defaults,
...this.all
};
}
}
get size() {
return Object.keys(this.all || {}).length;
}
get(key) {
return dotProp.get(this.all, key);
}
set(key, value) {
const config = this.all;
if (arguments.length === 1) {
for (const k of Object.keys(key)) {
dotProp.set(config, k, key[k]);
}
} else {
dotProp.set(config, key, value);
}
this.all = config;
}
has(key) {
return dotProp.has(this.all, key);
}
delete(key) {
const config = this.all;
dotProp.delete(config, key);
this.all = config;
}
clear() {
this.all = {};
}
}
module.exports = Configstore;