Initial commit
[yaffs-website] / node_modules / dargs / index.js
1 'use strict';
2
3 function createArg(key, val) {
4         key = key.replace(/[A-Z]/g, '-$&').toLowerCase();
5         return '--' + key + (val ? '=' + val : '');
6 };
7
8 module.exports = function (opts, excludes, includes) {
9         var args = [];
10
11         Object.keys(opts).forEach(function (key) {
12                 var val = opts[key];
13
14                 if (Array.isArray(excludes) && excludes.indexOf(key) !== -1) {
15                         return;
16                 }
17
18                 if (Array.isArray(includes) && includes.indexOf(key) === -1) {
19                         return;
20                 }
21
22                 if (val === true) {
23                         args.push(createArg(key));
24                 }
25
26                 if (typeof val === 'string') {
27                         args.push(createArg(key, val));
28                 }
29
30                 if (typeof val === 'number' && isNaN(val) === false) {
31                         args.push(createArg(key, '' + val));
32                 }
33
34                 if (Array.isArray(val)) {
35                         val.forEach(function (arrVal) {
36                                 args.push(createArg(key, arrVal));
37                         });
38                 }
39         });
40
41         return args;
42 };