-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (41 loc) · 986 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
/**
* Copyright (C) 2016 yanni4night.com
* index.js
*
* changelog
* 2016-07-05[13:07:33]:revised
* 2016-07-27[19:29:35]:support get all
*
* @author [email protected]
* @version 0.1.2
* @since 0.1.0
*/
'use strict';
const extend = require('lodash/extend');
const cloneDeep = require('lodash/cloneDeep');
const defineFrozenProperty = require('define-frozen-property');
class Options {
constructor(opts) {
defineFrozenProperty(this, '_options', extend({}, opts));
}
extend(extendable) {
extend(this._options, extendable);
return this;
}
has(key) {
return key in this._options;
}
get(key, defaultValue) {
if(!key) {
return cloneDeep(this._options);
}
return this.has(key) ? this._options[key] : defaultValue;
}
set(key, value) {
return (this._options[key] = value);
}
rm(key) {
return delete this._options[key];
}
}
module.exports = Options;