aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/dargs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/dargs.js')
-rw-r--r--src/dargs.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/dargs.js b/src/dargs.js
new file mode 100644
index 0000000..e5c574c
--- /dev/null
+++ b/src/dargs.js
@@ -0,0 +1,16 @@
1'use strict';
2
3function dargs(obj) {
4 return Object.keys(obj).reduce((args, key) => {
5 const arg = '--' + key.replace(/[A-Z]/g, '-$&').toLowerCase();
6 const val = obj[key]
7
8 if (key === '_') val.forEach(v => args.push(v))
9 else if (Array.isArray(val)) val.forEach(v => args.push(arg, v))
10 else args.push(arg, obj[key])
11
12 return args.filter(arg => (typeof arg !== 'boolean'))
13 }, [])
14}
15
16module.exports = dargs;