Socket
Socket
Sign inDemoInstall

yargs-unparser

Package Overview
Dependencies
4
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.4 to 2.0.0

11

CHANGELOG.md

@@ -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)

12

package.json
{
"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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc