yargs-unparser
Advanced tools
Comparing version 1.6.4 to 2.0.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [2.0.0](https://www.github.com/yargs/yargs-unparser/compare/v1.6.4...v2.0.0) (2020-10-02) | ||
### ⚠ BREAKING CHANGES | ||
* upgrade deps drop Node 6/8 (#71) | ||
### Code Refactoring | ||
* upgrade deps drop Node 6/8 ([#71](https://www.github.com/yargs/yargs-unparser/issues/71)) ([c686882](https://www.github.com/yargs/yargs-unparser/commit/c686882f5ad554be44169e3745e741cb4ec898d0)) | ||
### [1.6.4](https://www.github.com/yargs/yargs-unparser/compare/v1.6.3...v1.6.4) (2020-10-01) | ||
@@ -7,0 +18,0 @@ |
39
index.js
'use strict'; | ||
const yargs = require('yargs/yargs'); | ||
const flatten = require('flat'); | ||
@@ -27,2 +26,36 @@ const camelcase = require('camelcase'); | ||
function parseCommand(cmd) { | ||
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' '); | ||
const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/); | ||
const bregex = /\.*[\][<>]/g; | ||
const firstCommand = splitCommand.shift(); | ||
if (!firstCommand) { throw new Error(`No command found in: ${cmd}`); } | ||
const parsedCommand = { | ||
cmd: firstCommand.replace(bregex, ''), | ||
demanded: [], | ||
optional: [], | ||
}; | ||
splitCommand.forEach((cmd, i) => { | ||
let variadic = false; | ||
cmd = cmd.replace(/\s/g, ''); | ||
if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1) { variadic = true; } | ||
if (/^\[/.test(cmd)) { | ||
parsedCommand.optional.push({ | ||
cmd: cmd.replace(bregex, '').split('|'), | ||
variadic, | ||
}); | ||
} else { | ||
parsedCommand.demanded.push({ | ||
cmd: cmd.replace(bregex, '').split('|'), | ||
variadic, | ||
}); | ||
} | ||
}); | ||
return parsedCommand; | ||
} | ||
function unparseOption(key, value, unparsed) { | ||
@@ -58,5 +91,3 @@ if (typeof value === 'string') { | ||
const { 0: cmd, index } = options.command.match(/[^<[]*/); | ||
const { demanded, optional } = yargs() | ||
.getCommandInstance() | ||
.parseCommand(`foo ${options.command.substr(index + cmd.length)}`); | ||
const { demanded, optional } = parseCommand(`foo ${options.command.substr(index + cmd.length)}`); | ||
@@ -63,0 +94,0 @@ // Push command (can be a deep command) |
{ | ||
"name": "yargs-unparser", | ||
"description": "Converts back a yargs argv object to its original array form", | ||
"version": "1.6.4", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -14,3 +14,3 @@ "yargs", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=10" | ||
}, | ||
@@ -24,2 +24,3 @@ "homepage": "https://github.com/yargs/yargs-unparser", | ||
"lint": "eslint .", | ||
"fix": "eslint . --fix", | ||
"test": "jest --env node --coverage", | ||
@@ -45,8 +46,7 @@ "prerelease": "npm t && npm run lint", | ||
"dependencies": { | ||
"camelcase": "^5.3.1", | ||
"decamelize": "^1.2.0", | ||
"camelcase": "^6.0.0", | ||
"decamelize": "^4.0.0", | ||
"flat": "^5.0.2", | ||
"is-plain-obj": "^1.1.0", | ||
"yargs": "^14.2.3" | ||
"is-plain-obj": "^2.1.0" | ||
} | ||
} |
@@ -78,5 +78,10 @@ # yargs-unparser | ||
## Supported Node.js Versions | ||
Libraries in this ecosystem make a best effort to track | ||
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a | ||
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a). | ||
## License | ||
[MIT License](http://opensource.org/licenses/MIT) |
13860
4
134
87
+ Addedcamelcase@6.3.0(transitive)
+ Addeddecamelize@4.0.0(transitive)
+ Addedis-plain-obj@2.1.0(transitive)
- Removedyargs@^14.2.3
- Removedansi-regex@4.1.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedcliui@5.0.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedemoji-regex@7.0.3(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedis-fullwidth-code-point@2.0.0(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedstring-width@3.1.0(transitive)
- Removedstrip-ansi@5.2.0(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@5.1.0(transitive)
- Removedy18n@4.0.3(transitive)
- Removedyargs@14.2.3(transitive)
- Removedyargs-parser@15.0.3(transitive)
Updatedcamelcase@^6.0.0
Updateddecamelize@^4.0.0
Updatedis-plain-obj@^2.1.0