index.js
816 字节
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
'use strict';
function createArg(key, val) {
key = key.replace(/[A-Z]/g, '-$&').toLowerCase();
return '--' + key + (val ? '=' + val : '');
};
module.exports = function (opts, excludes, includes) {
var args = [];
Object.keys(opts).forEach(function (key) {
var val = opts[key];
if (Array.isArray(excludes) && excludes.indexOf(key) !== -1) {
return;
}
if (Array.isArray(includes) && includes.indexOf(key) === -1) {
return;
}
if (val === true) {
args.push(createArg(key));
}
if (typeof val === 'string') {
args.push(createArg(key, val));
}
if (typeof val === 'number' && isNaN(val) === false) {
args.push(createArg(key, '' + val));
}
if (Array.isArray(val)) {
val.forEach(function (arrVal) {
args.push(createArg(key, arrVal));
});
}
});
return args;
};