tiny-parse-argv
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -74,3 +74,3 @@ /* IMPORT */ | ||
const parseCharSeparator = (argv) => { | ||
const re = /^-([a-zA-Z0-9]{2,})([^]*)$/; | ||
const re = /^-([a-zA-Z0-9\.]{2,})([^]*)$/; | ||
return parseWithRegExp(argv, re, (_, chars) => chars.split('').map(char => `-${char}`)); | ||
@@ -77,0 +77,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"description": "A tiny function for parsing process.argv, a modern rewrite of a sensible subset of minimist.", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
@@ -24,2 +24,4 @@ # Tiny Parse Argv | ||
- `options.default`: an object containing default values, which will be used if not overridded by the `argv` array. | ||
- `options.incompatible`: an object mapping flags with other flags they are incompatible with. | ||
- `options.onIncompatible`: a function that will be called if any pairs of flags that are incompatible with each other is detected. | ||
- `options.onInvalid`: a function that will be called if any of the provided flags have an invalid value, e.g. a boolean value for a string flag. | ||
@@ -26,0 +28,0 @@ - `options.onMissing`: a function that will be called if any of the required flags is missing. If a default value is provided for a flag it won't be considered as missing. |
@@ -135,3 +135,3 @@ | ||
const re = /^-([a-zA-Z0-9]{2,})([^]*)$/; | ||
const re = /^-([a-zA-Z0-9\.]{2,})([^]*)$/; | ||
@@ -138,0 +138,0 @@ return parseWithRegExp ( argv, re, ( _, chars ) => chars.split ( '' ).map ( char => `-${char}` ) ); |
@@ -170,2 +170,18 @@ | ||
it ( 'supports dotted shorthand flag, with implicit splits', t => { | ||
parse ( t, { | ||
input: ['-.abc'], | ||
output: { | ||
'.': true, | ||
a: true, | ||
b: true, | ||
c: true, | ||
_: [], | ||
'--': [] | ||
} | ||
}); | ||
}); | ||
it ( 'supports dotted longhand flags', t => { | ||
@@ -275,2 +291,38 @@ | ||
it ( 'detects the following in this order: unknown, missing, invalid, incompatible', t => { | ||
const order = []; | ||
const expected = ['unknown', 'missing', 'invalid', 'incompatible']; | ||
parse ( t, { | ||
input: ['--unknown', '--bool', '--incompatible'], | ||
options: { | ||
string: ['bool'], | ||
required: ['missing'], | ||
incompatible: { 'bool': ['incompatible'] }, | ||
onIncompatible () { | ||
order.push ( 'incompatible' ); | ||
}, | ||
onMissing () { | ||
order.push ( 'missing' ); | ||
}, | ||
onInvalid () { | ||
order.push ( 'invalid' ); | ||
}, | ||
onUnknown () { | ||
order.push ( 'unknown' ); | ||
} | ||
}, | ||
output: { | ||
unknown: true, | ||
incompatible: true, | ||
_: [], | ||
'--': [] | ||
} | ||
}); | ||
t.deepEqual ( order, expected ); | ||
}); | ||
// bool: https://github.com/minimistjs/minimist/blob/main/test/bool.js | ||
@@ -277,0 +329,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53141
1769
63