options-helper.js
1.09 KB
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
var isArray = require('./array-helper').isArray;
module.exports = {
copyOptions: function (options) {
var key, copy = {};
for (key in options) {
if (options.hasOwnProperty(key)) {
copy[key] = options[key];
}
}
return copy;
},
ensureFlagExists: function (item, options) {
if (!(item in options) || typeof options[item] !== 'boolean') {
options[item] = false;
}
},
ensureSpacesExists: function (options) {
if (!('spaces' in options) || (typeof options.spaces !== 'number' && typeof options.spaces !== 'string')) {
options.spaces = 0;
}
},
ensureAlwaysArrayExists: function (options) {
if (!('alwaysArray' in options) || (typeof options.alwaysArray !== 'boolean' && !isArray(options.alwaysArray))) {
options.alwaysArray = false;
}
},
ensureKeyExists: function (key, options) {
if (!(key + 'Key' in options) || typeof options[key + 'Key'] !== 'string') {
options[key + 'Key'] = options.compact ? '_' + key : key;
}
},
checkFnExists: function (key, options) {
return key + 'Fn' in options;
}
};