diff options
author | eric thul <thul.eric@gmail.com> | 2016-06-12 15:17:44 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2016-06-12 15:17:44 -0400 |
commit | 531c751fe5593750a377db38bcfaf9a5383ac661 (patch) | |
tree | 935b5f17cc29bee58e27b474fe604a3257b7fc63 /src/dargs.js | |
parent | 7243be70a2163be2230a5f2739768137305a24ef (diff) | |
download | purs-loader-531c751fe5593750a377db38bcfaf9a5383ac661.tar.gz purs-loader-531c751fe5593750a377db38bcfaf9a5383ac661.tar.zst purs-loader-531c751fe5593750a377db38bcfaf9a5383ac661.zip |
Reduce building of PureScript module map
Resolves #59 and resolves #60
Diffstat (limited to 'src/dargs.js')
-rw-r--r-- | src/dargs.js | 16 |
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 | |||
3 | function 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 | |||
16 | module.exports = dargs; | ||