Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiny-parse-argv

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-parse-argv - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

16

dist/index.js

@@ -66,7 +66,7 @@ /* IMPORT */

};
const setAliased = (target, key, value, variadic, aliases) => {
const setAliased = (target, key, value, unary, variadic, aliases) => {
const set = variadic ? setVariadic : setNormal;
set(target, key, value);
set(target, key, value, unary);
aliases[key]?.forEach(alias => {
set(target, alias, value);
set(target, alias, value, unary);
});

@@ -158,2 +158,3 @@ };

const eagers = getAliasedSet(aliases, options.eager);
const unarys = getAliasedSet(aliases, options.unary);
const variadics = getAliasedSet(aliases, options.variadic);

@@ -182,5 +183,6 @@ const defaults = getAliasedDefaults(aliases, options.default);

if (!integers.has(key) && !numbers.has(key) && !strings.has(key)) { // String options shouldn't have an inferred value
const unary = unarys.has(key);
const variadic = variadics.has(key);
const value = variadic ? [positive] : positive;
setAliased(parsed, key, value, variadic, aliases);
setAliased(parsed, key, value, unary, variadic, aliases);
}

@@ -196,4 +198,5 @@ }

if (!isNull(value)) {
const unary = unarys.has(optionPrev);
const variadic = variadics.has(optionPrev);
setAliased(parsed, optionPrev, value, variadic, aliases);
setAliased(parsed, optionPrev, value, unary, variadic, aliases);
}

@@ -203,4 +206,5 @@ }

if (!isNull(value)) {
const unary = unarys.has(optionEagerPrev);
const variadic = variadics.has(optionEagerPrev);
setAliased(parsed, optionEagerPrev, value, variadic, aliases);
setAliased(parsed, optionEagerPrev, value, unary, variadic, aliases);
}

@@ -207,0 +211,0 @@ }

@@ -8,2 +8,3 @@ type Options = {

required?: string[];
unary?: string[];
variadic?: string[];

@@ -10,0 +11,0 @@ alias?: Partial<Record<string, string[]>>;

@@ -7,4 +7,4 @@ declare const castArray: <T>(value: T | T[]) => T[];

declare const isUndefined: (value: unknown) => value is undefined;
declare const setNormal: (target: any, key: string, value: any) => void;
declare const setVariadic: (target: any, key: string, value: any) => void;
declare const setNormal: (target: any, key: string, value: any, override: boolean) => void;
declare const setVariadic: (target: any, key: string, value: any, override: boolean) => void;
declare const uniq: <T>(values: T[]) => T[];

@@ -11,0 +11,0 @@ declare const uniqBy: <T>(values: T[], iterator: (value: T, index: number, arr: ArrayLike<T>) => unknown) => T[];

@@ -20,4 +20,7 @@ /* MAIN */

};
const setNormal = (target, key, value) => {
if (Array.isArray(target[key])) {
const setNormal = (target, key, value, override) => {
if (override) {
target[key] = value;
}
else if (Array.isArray(target[key])) {
target[key].push(value);

@@ -32,5 +35,8 @@ }

};
const setVariadic = (target, key, value) => {
const setVariadic = (target, key, value, override) => {
const values = castArray(value);
if (Array.isArray(target[key])) {
if (override) {
target[key] = values;
}
else if (Array.isArray(target[key])) {
target[key].push(...values);

@@ -37,0 +43,0 @@ }

@@ -5,3 +5,3 @@ {

"description": "A tiny function for parsing process.argv, a modern rewrite of a sensible subset of minimist.",
"version": "2.7.0",
"version": "2.8.0",
"type": "module",

@@ -8,0 +8,0 @@ "main": "dist/index.js",

@@ -22,2 +22,3 @@ # Tiny Parse Argv

- `options.eager`: the listed flags are considered to be eager, and will consume multiple consecutive non-flag values.
- `options.unary`: the listed flags are considered to be unary, and if multiple values are provided only the last one will be considered.
- `options.variadic`: the listed flags are considered to be variadic, and their value, if present, will always be an array.

@@ -24,0 +25,0 @@ - `options.required`: the listed flags are considered to be required, if some are missing `options.onMissing` will be called.

@@ -120,11 +120,11 @@

const setAliased = ( target: any, key: string, value: any, variadic: boolean, aliases: Partial<Record<string, string[]>> ): void => {
const setAliased = ( target: any, key: string, value: any, unary: boolean, variadic: boolean, aliases: Partial<Record<string, string[]>> ): void => {
const set = variadic ? setVariadic : setNormal;
set ( target, key, value );
set ( target, key, value, unary );
aliases[key]?.forEach ( alias => {
set ( target, alias, value );
set ( target, alias, value, unary );

@@ -278,2 +278,3 @@ });

const eagers = getAliasedSet ( aliases, options.eager );
const unarys = getAliasedSet ( aliases, options.unary );
const variadics = getAliasedSet ( aliases, options.variadic );

@@ -311,6 +312,7 @@ const defaults = getAliasedDefaults ( aliases, options.default );

const unary = unarys.has ( key );
const variadic = variadics.has ( key );
const value = variadic ? [positive] : positive;
setAliased ( parsed, key, value, variadic, aliases );
setAliased ( parsed, key, value, unary, variadic, aliases );

@@ -334,5 +336,6 @@ }

const unary = unarys.has ( optionPrev );
const variadic = variadics.has ( optionPrev );
setAliased ( parsed, optionPrev, value, variadic, aliases );
setAliased ( parsed, optionPrev, value, unary, variadic, aliases );

@@ -345,5 +348,6 @@ }

const unary = unarys.has ( optionEagerPrev );
const variadic = variadics.has ( optionEagerPrev );
setAliased ( parsed, optionEagerPrev, value, variadic, aliases );
setAliased ( parsed, optionEagerPrev, value, unary, variadic, aliases );

@@ -350,0 +354,0 @@ }

@@ -13,2 +13,3 @@

required?: string[],
unary?: string[],
variadic?: string[],

@@ -15,0 +16,0 @@ alias?: Partial<Record<string, string[]>>,

@@ -40,6 +40,10 @@

const setNormal = ( target: any, key: string, value: any ): void => {
const setNormal = ( target: any, key: string, value: any, override: boolean ): void => {
if ( Array.isArray ( target[key] ) ) {
if ( override ) {
target[key] = value;
} else if ( Array.isArray ( target[key] ) ) {
target[key].push ( value );

@@ -59,8 +63,12 @@

const setVariadic = ( target: any, key: string, value: any ): void => {
const setVariadic = ( target: any, key: string, value: any, override: boolean ): void => {
const values = castArray ( value );
if ( Array.isArray ( target[key] ) ) {
if ( override ) {
target[key] = values;
} else if ( Array.isArray ( target[key] ) ) {
target[key].push ( ...values );

@@ -67,0 +75,0 @@

@@ -320,2 +320,25 @@

it ( 'supports explicitly unary flags', t => {
parse ( t, {
input: ['--bool', '--str', '--no-foo', '--bar', 'one', '--baz', 'one', '--baz', 'one', '--qux', 'one', 'two'],
options: {
boolean: ['bool', 'foo'],
string: ['str', 'bar', 'baz'],
eager: ['qux'],
unary: ['bool', 'str', 'foo', 'bar', 'baz', 'qux'],
},
output: {
bool: true,
foo: false,
bar: 'one',
baz: 'one',
qux: 'two',
_: [],
'--': []
}
});
});
it ( 'supports explicitly variadic flags', t => {

@@ -322,0 +345,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc