diff options
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/minimist-options/index.js')
-rw-r--r-- | bin/wiki/ImportarDesdeURL/node_modules/minimist-options/index.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/minimist-options/index.js b/bin/wiki/ImportarDesdeURL/node_modules/minimist-options/index.js new file mode 100644 index 00000000..7757d376 --- /dev/null +++ b/bin/wiki/ImportarDesdeURL/node_modules/minimist-options/index.js @@ -0,0 +1,77 @@ +'use strict'; + +const isPlainObject = require('is-plain-obj'); +const arrify = require('arrify'); + +const push = (obj, prop, value) => { + if (!obj[prop]) { + obj[prop] = []; + } + + obj[prop].push(value); +}; + +const insert = (obj, prop, key, value) => { + if (!obj[prop]) { + obj[prop] = {}; + } + + obj[prop][key] = value; +}; + +const passthroughOptions = ['stopEarly', 'unknown', '--']; + +module.exports = options => { + options = options || {}; + + const result = {}; + + passthroughOptions.forEach(key => { + if (options[key]) { + result[key] = options[key]; + } + }); + + Object.keys(options).forEach(key => { + let value = options[key]; + + if (key === 'arguments') { + key = '_'; + } + + // If short form is used + // convert it to long form + // e.g. { 'name': 'string' } + if (typeof value === 'string') { + value = {type: value}; + } + + if (isPlainObject(value)) { + const props = value; + + if (props.type) { + const type = props.type; + + if (type === 'string') { + push(result, 'string', key); + } + + if (type === 'boolean') { + push(result, 'boolean', key); + } + } + + const aliases = arrify(props.alias); + + aliases.forEach(alias => { + insert(result, 'alias', alias, key); + }); + + if ({}.hasOwnProperty.call(props, 'default')) { + insert(result, 'default', key, props.default); + } + } + }); + + return result; +}; |