.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / minimist-options / index.js
diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/minimist-options/index.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/minimist-options/index.js
new file mode 100644 (file)
index 0000000..7757d37
--- /dev/null
@@ -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;
+};