yargs-parser
Advanced tools
Comparing version 20.2.7 to 20.2.9
@@ -1,3 +0,9 @@ | ||
// Main entrypoint for libraries using yargs-parser in Node.js | ||
// CJS and ESM environments: | ||
/** | ||
* @fileoverview Main entrypoint for libraries using yargs-parser in Node.js | ||
* CJS and ESM environments. | ||
* | ||
* @license | ||
* Copyright (c) 2016, Contributors | ||
* SPDX-License-Identifier: ISC | ||
*/ | ||
import { format } from 'util'; | ||
@@ -4,0 +10,0 @@ import { readFileSync } from 'fs'; |
@@ -0,1 +1,6 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2016, Contributors | ||
* SPDX-License-Identifier: ISC | ||
*/ | ||
export function camelCase(str) { | ||
@@ -6,3 +11,3 @@ // Handle the case where an argument is provided as camel case, e.g., fooBar. | ||
if (!isCamelCase) { | ||
str = str.toLocaleLowerCase(); | ||
str = str.toLowerCase(); | ||
} | ||
@@ -20,3 +25,3 @@ if (str.indexOf('-') === -1 && str.indexOf('_') === -1) { | ||
nextChrUpper = false; | ||
chr = chr.toLocaleUpperCase(); | ||
chr = chr.toUpperCase(); | ||
} | ||
@@ -34,3 +39,3 @@ if (i !== 0 && (chr === '-' || chr === '_')) { | ||
export function decamelize(str, joinString) { | ||
const lowercase = str.toLocaleLowerCase(); | ||
const lowercase = str.toLowerCase(); | ||
joinString = joinString || '-'; | ||
@@ -60,5 +65,5 @@ let notCamelcase = ''; | ||
// don't treat 0123 as a number; as it drops the leading '0'. | ||
if (x.length > 1 && x[0] === '0') | ||
if (/^0[^.]/.test(x)) | ||
return false; | ||
return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x); | ||
} |
@@ -0,1 +1,6 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2016, Contributors | ||
* SPDX-License-Identifier: ISC | ||
*/ | ||
// take an un-split argv string and tokenize it. | ||
@@ -2,0 +7,0 @@ export function tokenizeArgString(argString) { |
@@ -1,1 +0,12 @@ | ||
export {}; | ||
/** | ||
* @license | ||
* Copyright (c) 2016, Contributors | ||
* SPDX-License-Identifier: ISC | ||
*/ | ||
export var DefaultValuesForTypeKey; | ||
(function (DefaultValuesForTypeKey) { | ||
DefaultValuesForTypeKey["BOOLEAN"] = "boolean"; | ||
DefaultValuesForTypeKey["STRING"] = "string"; | ||
DefaultValuesForTypeKey["NUMBER"] = "number"; | ||
DefaultValuesForTypeKey["ARRAY"] = "array"; | ||
})(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {})); |
@@ -0,2 +1,8 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2016, Contributors | ||
* SPDX-License-Identifier: ISC | ||
*/ | ||
import { tokenizeArgString } from './tokenize-arg-string.js'; | ||
import { DefaultValuesForTypeKey } from './yargs-parser-types.js'; | ||
import { camelCase, decamelize, looksLikeNumber } from './string-utils.js'; | ||
@@ -164,2 +170,3 @@ let mixin; | ||
const arg = args[i]; | ||
const truncatedArg = arg.replace(/^-{3,}/, '---'); | ||
let broken; | ||
@@ -176,3 +183,3 @@ let key; | ||
} | ||
else if (arg.match(/---+(=|$)/)) { | ||
else if (truncatedArg.match(/---+(=|$)/)) { | ||
// options without key name are invalid. | ||
@@ -893,2 +900,3 @@ pushPositional(arg); | ||
function isUnknownOption(arg) { | ||
arg = arg.replace(/^-{3,}/, '--'); | ||
// ignore negative numbers | ||
@@ -930,6 +938,6 @@ if (arg.match(negative)) { | ||
const def = { | ||
boolean: true, | ||
string: '', | ||
number: undefined, | ||
array: [] | ||
[DefaultValuesForTypeKey.BOOLEAN]: true, | ||
[DefaultValuesForTypeKey.STRING]: '', | ||
[DefaultValuesForTypeKey.NUMBER]: undefined, | ||
[DefaultValuesForTypeKey.ARRAY]: [] | ||
}; | ||
@@ -940,11 +948,11 @@ return def[type]; | ||
function guessType(key) { | ||
let type = 'boolean'; | ||
let type = DefaultValuesForTypeKey.BOOLEAN; | ||
if (checkAllAliases(key, flags.strings)) | ||
type = 'string'; | ||
type = DefaultValuesForTypeKey.STRING; | ||
else if (checkAllAliases(key, flags.numbers)) | ||
type = 'number'; | ||
type = DefaultValuesForTypeKey.NUMBER; | ||
else if (checkAllAliases(key, flags.bools)) | ||
type = 'boolean'; | ||
type = DefaultValuesForTypeKey.BOOLEAN; | ||
else if (checkAllAliases(key, flags.arrays)) | ||
type = 'array'; | ||
type = DefaultValuesForTypeKey.ARRAY; | ||
return type; | ||
@@ -951,0 +959,0 @@ } |
@@ -5,2 +5,18 @@ # Changelog | ||
### [20.2.9](https://www.github.com/yargs/yargs-parser/compare/yargs-parser-v20.2.8...yargs-parser-v20.2.9) (2021-06-20) | ||
### Bug Fixes | ||
* **build:** fixed automated release pipeline ([1fe9135](https://www.github.com/yargs/yargs-parser/commit/1fe9135884790a083615419b2861683e2597dac3)) | ||
### [20.2.8](https://www.github.com/yargs/yargs-parser/compare/yargs-parser-v20.2.7...yargs-parser-v20.2.8) (2021-06-20) | ||
### Bug Fixes | ||
* **locale:** Turkish camelize and decamelize issues with toLocaleLowerCase/toLocaleUpperCase ([2617303](https://www.github.com/yargs/yargs-parser/commit/261730383e02448562f737b94bbd1f164aed5143)) | ||
* **perf:** address slow parse when using unknown-options-as-args ([#394](https://www.github.com/yargs/yargs-parser/issues/394)) ([441f059](https://www.github.com/yargs/yargs-parser/commit/441f059d585d446551068ad213db79ac91daf83a)) | ||
* **string-utils:** detect [0,1] ranged values as numbers ([#388](https://www.github.com/yargs/yargs-parser/issues/388)) ([efcc32c](https://www.github.com/yargs/yargs-parser/commit/efcc32c2d6b09aba31abfa2db9bd947befe5586b)) | ||
### [20.2.7](https://www.github.com/yargs/yargs-parser/compare/v20.2.6...v20.2.7) (2021-03-10) | ||
@@ -11,3 +27,3 @@ | ||
* **deno:** force relese for Deno ([6687c97](https://www.github.com/yargs/yargs-parser/commit/6687c972d0f3ca7865a97908dde3080b05f8b026)) | ||
* **deno:** force release for Deno ([6687c97](https://www.github.com/yargs/yargs-parser/commit/6687c972d0f3ca7865a97908dde3080b05f8b026)) | ||
@@ -14,0 +30,0 @@ ### [20.2.6](https://www.github.com/yargs/yargs-parser/compare/v20.2.5...v20.2.6) (2021-02-22) |
{ | ||
"name": "yargs-parser", | ||
"version": "20.2.7", | ||
"version": "20.2.9", | ||
"description": "the mighty option parser used by yargs", | ||
@@ -52,3 +52,3 @@ "main": "build/index.cjs", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^10.0.3", | ||
"@types/node": "^14.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.10.1", | ||
@@ -64,8 +64,8 @@ "@typescript-eslint/parser": "^3.10.1", | ||
"gts": "^3.0.0", | ||
"mocha": "^8.0.0", | ||
"puppeteer": "^8.0.0", | ||
"mocha": "^9.0.0", | ||
"puppeteer": "^10.0.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.22.1", | ||
"rollup-plugin-cleanup": "^3.1.1", | ||
"serve": "^11.3.2", | ||
"serve": "^12.0.0", | ||
"standardx": "^7.0.0", | ||
@@ -72,0 +72,0 @@ "start-server-and-test": "^1.11.2", |
@@ -12,3 +12,3 @@ # yargs-parser | ||
<img width="250" src="https://raw.githubusercontent.com/yargs/yargs-parser/master/yargs-logo.png"> | ||
<img width="250" src="https://raw.githubusercontent.com/yargs/yargs-parser/main/yargs-logo.png"> | ||
@@ -340,3 +340,3 @@ ## Example | ||
$ node example --arr 1 2 | ||
{ _[], arr: [1, 2] } | ||
{ _: [], arr: [1, 2] } | ||
``` | ||
@@ -348,3 +348,3 @@ | ||
$ node example --arr 1 2 | ||
{ _[2], arr: [1] } | ||
{ _: [2], arr: [1] } | ||
``` | ||
@@ -351,0 +351,0 @@ |
Sorry, the diff of this file is not supported yet
124417
2275