blob: e5c574c23557a7b89ad70be61765d07b34498281 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
'use strict';
function dargs(obj) {
return Object.keys(obj).reduce((args, key) => {
const arg = '--' + key.replace(/[A-Z]/g, '-$&').toLowerCase();
const val = obj[key]
if (key === '_') val.forEach(v => args.push(v))
else if (Array.isArray(val)) val.forEach(v => args.push(arg, v))
else args.push(arg, obj[key])
return args.filter(arg => (typeof arg !== 'boolean'))
}, [])
}
module.exports = dargs;
|