-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
101 lines (83 loc) · 1.48 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Make `obj` configurable.
*
* @param {Object} obj
* @return {Object} the `obj`
* @api public
*/
module.exports = function(obj){
/**
* Mixin settings.
*/
obj.settings = {};
/**
* Set config `name` to `val`, or
* multiple with an object.
*
* @param {String|Object} name
* @param {Mixed} val
* @return {Object} self
* @api public
*/
obj.set = function(name, val){
if (1 == arguments.length) {
for (var key in name) {
this.set(key, name[key]);
}
} else {
this.settings[name] = val;
}
return this;
};
/**
* Get setting `name`.
*
* @param {String} name
* @return {Mixed}
* @api public
*/
obj.get = function(name){
return this.settings[name];
};
/**
* Enable `name`.
*
* @param {String} name
* @return {Object} self
* @api public
*/
obj.enable = function(name){
return this.set(name, true);
};
/**
* Disable `name`.
*
* @param {String} name
* @return {Object} self
* @api public
*/
obj.disable = function(name){
return this.set(name, false);
};
/**
* Check if `name` is enabled.
*
* @param {String} name
* @return {Boolean}
* @api public
*/
obj.enabled = function(name){
return !! this.get(name);
};
/**
* Check if `name` is disabled.
*
* @param {String} name
* @return {Boolean}
* @api public
*/
obj.disabled = function(name){
return ! this.get(name);
};
return obj;
};