added unit testing, and started implementing unit tests...phew
This commit is contained in:
27
node_modules/yargs-unparser/CHANGELOG.md
generated
vendored
Normal file
27
node_modules/yargs-unparser/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
<a name="1.5.0"></a>
|
||||
# 1.5.0 (2018-11-30)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **package:** update yargs to version 10.0.3 ([f1eb4cb](https://github.com/yargs/yargs-unparser/commit/f1eb4cb))
|
||||
* **package:** update yargs to version 11.0.0 ([6aa7c91](https://github.com/yargs/yargs-unparser/commit/6aa7c91))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add interoperation with minimist ([ba477f5](https://github.com/yargs/yargs-unparser/commit/ba477f5))
|
||||
|
||||
|
||||
|
||||
<a name="1.4.0"></a>
|
||||
# [1.4.0](https://github.com/moxystudio/yargs-unparser/compare/v1.3.0...v1.4.0) (2017-12-30)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add interoperation with minimist ([ba477f5](https://github.com/moxystudio/yargs-unparser/commit/ba477f5))
|
21
node_modules/yargs-unparser/LICENSE
generated
vendored
Normal file
21
node_modules/yargs-unparser/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Made With MOXY Lda <hello@moxy.studio>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
91
node_modules/yargs-unparser/README.md
generated
vendored
Normal file
91
node_modules/yargs-unparser/README.md
generated
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
# yargs-unparser
|
||||
|
||||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]
|
||||
|
||||
[npm-url]:https://npmjs.org/package/yargs-unparser
|
||||
[npm-image]:http://img.shields.io/npm/v/yargs-unparser.svg
|
||||
[downloads-image]:http://img.shields.io/npm/dm/yargs-unparser.svg
|
||||
[travis-url]:https://travis-ci.org/yargs/yargs-unparser
|
||||
[travis-image]:http://img.shields.io/travis/yargs/yargs-unparser/master.svg
|
||||
[codecov-url]:https://codecov.io/gh/yargs/yargs-unparser
|
||||
[codecov-image]:https://img.shields.io/codecov/c/github/yargs/yargs-unparser/master.svg
|
||||
[david-dm-url]:https://david-dm.org/yargs/yargs-unparser
|
||||
[david-dm-image]:https://img.shields.io/david/yargs/yargs-unparser.svg
|
||||
[david-dm-dev-url]:https://david-dm.org/yargs/yargs-unparser?type=dev
|
||||
[david-dm-dev-image]:https://img.shields.io/david/dev/yargs/yargs-unparser.svg
|
||||
[greenkeeper-image]:https://badges.greenkeeper.io/yargs/yargs-unparser.svg
|
||||
[greenkeeper-url]:https://greenkeeper.io
|
||||
|
||||
Converts back a `yargs` argv object to its original array form.
|
||||
|
||||
Probably the unparser word doesn't even exist, but it sounds nice and goes well with [yargs-parser](https://github.com/yargs/yargs-parser).
|
||||
|
||||
The code originally lived in [MOXY](https://github.com/moxystudio)'s GitHub but was later moved here for discoverability.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
`$ npm install yargs-unparser`
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const parse = require('yargs-parser');
|
||||
const unparse = require('yargs-unparser');
|
||||
|
||||
const argv = parse(['--no-boolean', '--number', '4', '--string', 'foo'], {
|
||||
boolean: ['boolean'],
|
||||
number: ['number'],
|
||||
string: ['string'],
|
||||
});
|
||||
// { boolean: false, number: 4, string: 'foo', _: [] }
|
||||
|
||||
const unparsedArgv = unparse(argv);
|
||||
// ['--no-boolean', '--number', '4', '--string', 'foo'];
|
||||
```
|
||||
|
||||
The second argument of `unparse` accepts an options object:
|
||||
|
||||
- `alias`: The [aliases](https://github.com/yargs/yargs-parser#requireyargs-parserargs-opts) so that duplicate options aren't generated
|
||||
- `default`: The [default](https://github.com/yargs/yargs-parser#requireyargs-parserargs-opts) values so that the options with default values are omitted
|
||||
- `command`: The [command](https://github.com/yargs/yargs/blob/master/docs/advanced.md#commands) first argument so that command names and positional arguments are handled correctly
|
||||
|
||||
### Example with `command` options
|
||||
|
||||
```js
|
||||
const yargs = require('yargs');
|
||||
const unparse = require('yargs-unparse');
|
||||
|
||||
const argv = yargs
|
||||
.command('my-command <positional>', 'My awesome command', (yargs) =>
|
||||
yargs
|
||||
.option('boolean', { type: 'boolean' })
|
||||
.option('number', { type: 'number' })
|
||||
.option('string', { type: 'string' })
|
||||
)
|
||||
.parse(['my-command', 'hello', '--no-boolean', '--number', '4', '--string', 'foo']);
|
||||
// { positional: 'hello', boolean: false, number: 4, string: 'foo', _: ['my-command'] }
|
||||
|
||||
const unparsedArgv = unparse(argv, {
|
||||
command: 'my-command <positional>',
|
||||
});
|
||||
// ['my-command', 'hello', '--no-boolean', '--number', '4', '--string', 'foo'];
|
||||
```
|
||||
|
||||
### Caveats
|
||||
|
||||
The returned array can be parsed again by `yargs-parser` using the default configuration. If you used custom configuration that you want `yargs-unparser` to be aware, please fill an [issue](https://github.com/yargs/yargs-unparser/issues).
|
||||
|
||||
If you `coerce` in weird ways, things might not work correctly.
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
`$ npm test`
|
||||
`$ npm test -- --watch` during development
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT License](http://opensource.org/licenses/MIT)
|
130
node_modules/yargs-unparser/index.js
generated
vendored
Normal file
130
node_modules/yargs-unparser/index.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
const yargs = require('yargs/yargs');
|
||||
const flatten = require('flat');
|
||||
const castArray = require('lodash/castArray');
|
||||
const some = require('lodash/some');
|
||||
const isPlainObject = require('lodash/isPlainObject');
|
||||
const camelCase = require('lodash/camelCase');
|
||||
const kebabCase = require('lodash/kebabCase');
|
||||
const omitBy = require('lodash/omitBy');
|
||||
|
||||
function isAlias(key, alias) {
|
||||
return some(alias, (aliases) => castArray(aliases).indexOf(key) !== -1);
|
||||
}
|
||||
|
||||
function hasDefaultValue(key, value, defaults) {
|
||||
return value === defaults[key];
|
||||
}
|
||||
|
||||
function isCamelCased(key, argv) {
|
||||
return /[A-Z]/.test(key) && camelCase(key) === key && // Is it camel case?
|
||||
argv[kebabCase(key)] != null; // Is the standard version defined?
|
||||
}
|
||||
|
||||
function keyToFlag(key) {
|
||||
return key.length === 1 ? `-${key}` : `--${key}`;
|
||||
}
|
||||
|
||||
function unparseOption(key, value, unparsed) {
|
||||
if (typeof value === 'string') {
|
||||
unparsed.push(keyToFlag(key), value);
|
||||
} else if (value === true) {
|
||||
unparsed.push(keyToFlag(key));
|
||||
} else if (value === false) {
|
||||
unparsed.push(`--no-${key}`);
|
||||
} else if (Array.isArray(value)) {
|
||||
value.forEach((item) => unparseOption(key, item, unparsed));
|
||||
} else if (isPlainObject(value)) {
|
||||
const flattened = flatten(value, { safe: true });
|
||||
|
||||
for (const flattenedKey in flattened) {
|
||||
unparseOption(`${key}.${flattenedKey}`, flattened[flattenedKey], unparsed);
|
||||
}
|
||||
// Fallback case (numbers and other types)
|
||||
} else if (value != null) {
|
||||
unparsed.push(keyToFlag(key), `${value}`);
|
||||
}
|
||||
}
|
||||
|
||||
function unparsePositional(argv, options, unparsed) {
|
||||
const knownPositional = [];
|
||||
|
||||
// Unparse command if set, collecting all known positional arguments
|
||||
// e.g.: build <first> <second> <rest...>
|
||||
if (options.command) {
|
||||
const { 0: cmd, index } = options.command.match(/[^<[]*/);
|
||||
const { demanded, optional } = yargs()
|
||||
.getCommandInstance()
|
||||
.parseCommand(`foo ${options.command.substr(index + cmd.length)}`);
|
||||
|
||||
// Push command (can be a deep command)
|
||||
unparsed.push(...cmd.trim().split(/\s+/));
|
||||
|
||||
// Push positional arguments
|
||||
[...demanded, ...optional].forEach(({ cmd: cmds, variadic }) => {
|
||||
knownPositional.push(...cmds);
|
||||
|
||||
const cmd = cmds[0];
|
||||
const args = (variadic ? argv[cmd] || [] : [argv[cmd]])
|
||||
.filter((arg) => arg != null)
|
||||
.map((arg) => `${arg}`);
|
||||
|
||||
unparsed.push(...args);
|
||||
});
|
||||
}
|
||||
|
||||
// Unparse unkown positional arguments
|
||||
argv._ && unparsed.push(...argv._.slice(knownPositional.length));
|
||||
|
||||
return knownPositional;
|
||||
}
|
||||
|
||||
function unparseOptions(argv, options, knownPositional, unparsed) {
|
||||
const optionsArgv = omitBy(argv, (value, key) =>
|
||||
// Remove positional arguments
|
||||
knownPositional.includes(key) ||
|
||||
// Remove special _, -- and $0
|
||||
['_', '--', '$0'].includes(key) ||
|
||||
// Remove aliases
|
||||
isAlias(key, options.alias) ||
|
||||
// Remove default values
|
||||
hasDefaultValue(key, value, options.default) ||
|
||||
// Remove camel-cased
|
||||
isCamelCased(key, argv));
|
||||
|
||||
for (const key in optionsArgv) {
|
||||
unparseOption(key, optionsArgv[key], unparsed);
|
||||
}
|
||||
}
|
||||
|
||||
function unparseEndOfOptions(argv, options, unparsed) {
|
||||
// Unparse ending (--) arguments if set
|
||||
argv['--'] && unparsed.push('--', ...argv['--']);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
function unparser(argv, options) {
|
||||
options = Object.assign({
|
||||
alias: {},
|
||||
default: {},
|
||||
command: null,
|
||||
}, options);
|
||||
|
||||
const unparsed = [];
|
||||
|
||||
// Unparse known & unknown positional arguments (foo <first> <second> [rest...])
|
||||
// All known positional will be returned so that they are not added as flags
|
||||
const knownPositional = unparsePositional(argv, options, unparsed);
|
||||
|
||||
// Unparse option arguments (--foo hello --bar hi)
|
||||
unparseOptions(argv, options, knownPositional, unparsed);
|
||||
|
||||
// Unparse "end-of-options" arguments (stuff after " -- ")
|
||||
unparseEndOfOptions(argv, options, unparsed);
|
||||
|
||||
return unparsed;
|
||||
}
|
||||
|
||||
module.exports = unparser;
|
96
node_modules/yargs-unparser/package.json
generated
vendored
Normal file
96
node_modules/yargs-unparser/package.json
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
{
|
||||
"_from": "yargs-unparser@1.5.0",
|
||||
"_id": "yargs-unparser@1.5.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-HK25qidFTCVuj/D1VfNiEndpLIeJN78aqgR23nL3y4N0U/91cOAzqfHlF8n2BvoNDcZmJKin3ddNSvOxSr8flw==",
|
||||
"_location": "/yargs-unparser",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "yargs-unparser@1.5.0",
|
||||
"name": "yargs-unparser",
|
||||
"escapedName": "yargs-unparser",
|
||||
"rawSpec": "1.5.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.5.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mocha"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.5.0.tgz",
|
||||
"_shasum": "f2bb2a7e83cbc87bb95c8e572828a06c9add6e0d",
|
||||
"_spec": "yargs-unparser@1.5.0",
|
||||
"_where": "/Users/josh.burman/Projects/braid/node_modules/mocha",
|
||||
"author": {
|
||||
"name": "André Cruz",
|
||||
"email": "andre@moxy.studio"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/yargs/yargs-unparser/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"flat": "^4.1.0",
|
||||
"lodash": "^4.17.11",
|
||||
"yargs": "^12.0.5"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Converts back a yargs argv object to its original array form",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^7.2.1",
|
||||
"@commitlint/config-conventional": "^7.1.2",
|
||||
"eslint": "^5.9.0",
|
||||
"eslint-config-moxy": "^6.1.1",
|
||||
"husky": "^1.2.0",
|
||||
"jest": "^23.6.0",
|
||||
"lint-staged": "^8.1.0",
|
||||
"minimist": "^1.2.0",
|
||||
"standard-version": "^4.4.0",
|
||||
"yargs-parser": "^11.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"files": [],
|
||||
"homepage": "https://github.com/yargs/yargs-unparser",
|
||||
"keywords": [
|
||||
"yargs",
|
||||
"unparse",
|
||||
"expand",
|
||||
"inverse",
|
||||
"argv"
|
||||
],
|
||||
"license": "MIT",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"eslint --fix",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"main": "index.js",
|
||||
"name": "yargs-unparser",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/yargs/yargs-unparser.git"
|
||||
},
|
||||
"scripts": {
|
||||
"commitmsg": "commitlint -e $GIT_PARAMS",
|
||||
"lint": "eslint .",
|
||||
"precommit": "lint-staged",
|
||||
"prerelease": "npm t && npm run lint",
|
||||
"release": "standard-version",
|
||||
"test": "jest --env node --coverage"
|
||||
},
|
||||
"standard-version": {
|
||||
"scripts": {
|
||||
"posttag": "git push --follow-tags origin master && npm publish"
|
||||
}
|
||||
},
|
||||
"version": "1.5.0"
|
||||
}
|
Reference in New Issue
Block a user