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

argmate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argmate - npm Package Compare versions

Comparing version 0.4.0-beta to 0.4.1-beta

7

package.json
{
"name": "argmate",
"version": "0.4.0-beta",
"version": "0.4.1-beta",
"author": "Mathias Rengel Wulff",

@@ -34,4 +34,5 @@ "description": "Lightning-fast CLI parameter parsing, seasoned with convenient features for better DX",

"test-only": "bun test --bail",
"test-bundle": "sh test/test.with.bundle.sh",
"test-ci": "yarn test-format && yarn test && bun test --coverage",
"test-bundle": "sh test/test.bundle.sh",
"test-ci": "yarn test-format && yarn test && yarn test-cov",
"test-cov": "bun test --coverage --bail",
"test-perf-cli": "yarn test && cd bench/ && sh test-cli.sh",

@@ -38,0 +39,0 @@ "test-perf-js": "yarn test && cd bench/ && sh test-js.sh",

![mamate](https://github.com/mathiasrw/argmate/assets/1063454/bf9b4739-2e67-4103-97a7-b61d4fe9c6ca)
![mamate](https://github.com/mathiasrw/argmate/assets/1063454/b63fe097-dc1b-49c2-919e-cd665024e34d)

@@ -4,0 +4,0 @@ # ArgMate

@@ -44,4 +44,3 @@ // @ts-ignore

allowUnknown: true,
camelCaseUnknown: true,
kebabCaseAsAlias: true,
autoCamelKebabCase: true,
allowNegatingFlags: true,

@@ -53,6 +52,5 @@ allowKeyNumValues: true,

allowUnknown: false,
camelCaseUnknown: false,
autoCamelKebabCase: false,
allowNegatingFlags: false,
allowKeyNumValues: false,
kebabCaseAsAlias: false,
};

@@ -91,3 +89,2 @@

param.conflict = param.conflict || [];
param.type = param.type?.toLowerCase() || findType(param.default) || 'boolean';

@@ -97,7 +94,14 @@ if (undefined !== param.valid) {

if (undefined === param.default && Array.isArray(param.valid)) {
if (param.type.match(re.arrayType)) param.default = param.valid;
else if (1 < param.valid.length) param.default = param.valid[0];
if (!param.valid.length)
return conf.panic(`Empty array found for valid values of '${key}'`);
if (undefined === param.type) {
param.type = findType(param.valid[0]);
}
param.default = param.valid[0];
}
}
param.type = param.type?.toLowerCase() || findType(param.default) || 'boolean';
if (undefined !== param.default) {

@@ -108,3 +112,3 @@ if (Array.isArray(param.default)) {

return conf.error(
`Default parameters like "${param.default}" are not allowed on parameters like "${key}" with the type "${param.type}"`
`Default parameters like '${param.default}' are not allowed on parameters like '${key}' with the type '${param.type}'`
);

@@ -117,3 +121,3 @@ } else {

if ('count' == param.type) {
param = 0;
result[key] = 0;
}

@@ -130,3 +134,3 @@

if (conf.kebabCaseAsAlias) {
if (conf.autoCamelKebabCase) {
let kebab = key.replace(re.kebab, '$1-$2').toLowerCase();

@@ -177,11 +181,16 @@ if (kebab !== key) {

if (KEYNUM && (!conf.allowKeyNumValues || LONG || ASSIGN)) {
KEY = KEY + (KEYNUM ? KEYNUM : '');
KEYNUM = '';
if (KEYNUM) {
if (!conf.allowKeyNumValues || LONG || ASSIGN) {
KEY = KEY + (KEYNUM ? KEYNUM : '');
KEYNUM = '';
} else {
if (!LONG && 1 < KEY.length) {
return conf.error(
`Unsupported format: '${arg}'. Did you miss a dash before that?`
);
}
VAL = ASSIGN = KEYNUM;
}
}
if (KEYNUM && !LONG && 1 < KEY.length) {
return conf.error(`Unsupported format: "${arg}"`);
}
if (!LONG && 1 < KEY.length) {

@@ -199,5 +208,5 @@ const multi = KEY.split('').map(v => (NO ? '-no-' : '-') + v);

if (!conf.allowUnknown)
return conf.error(`Unspecified parameters like "${KEY}" not allowed.`);
return conf.error(`Unspecified parameters like '${KEY}' not allowed.`);
if (conf.camelCaseUnknown) {
if (conf.autoCamelKebabCase) {
KEY = KEY.replace(re.camel, function (match, letter) {

@@ -212,3 +221,3 @@ return letter.toUpperCase();

return conf.error(
`Expected one more parameter to fill the value of "${KEY}"`
`Expected one more parameter to fill the value of '${KEY}'`
);

@@ -228,3 +237,3 @@ VAL = args.pop() || '';

return conf.error(
`You asked for the parameter "${KEY}" to be boolean but you are trying to assign a value: "${arg}"`
`You asked for the parameter '${KEY}' to be boolean but you are trying to assign a value: '${arg}'`
);

@@ -236,3 +245,3 @@ result[params[KEY].key] = !NO;

if (NO) {
return conf.error(`Can't negate "${KEY}" as the type is set to "${params[KEY].type}"`);
return conf.error(`Can't negate '${KEY}' as the type is set to '${params[KEY].type}'`);
}

@@ -246,3 +255,3 @@

if (0 === args.length)
return conf.error(`Expected one more parameter to fill the value of "${KEY}"`);
return conf.error(`Expected one more parameter to fill the value of '${KEY}'`);

@@ -265,13 +274,2 @@ VAL ||= args.pop() || '';

case 'float':
num = +VAL;
break;
case 'int':
num = +VAL | 0;
break;
case 'hex':
num = parseInt(VAL, 16);
break;
case 'number[]':

@@ -282,12 +280,17 @@ case 'float[]':

case 'int':
case 'int[]':
debugger;
num = +VAL | 0;
if ('' + num !== VAL) num = NaN;
break;
case 'hex':
case 'hex[]':
num = parseInt(VAL, 16);
break;
default:
return conf.panic(
`The parameter "${KEY}" is configured with an invalid type: "${params[KEY].type}"`
`The parameter '${KEY}' is configured with an invalid type: '${params[KEY].type}'`
);

@@ -297,3 +300,3 @@ }

if (isNaN(num) || !isFinite(num))
return conf.error(`The value of "${KEY}" is not a valid ${params[KEY].type}: "${VAL}"`);
return conf.error(`The value of '${KEY}' is not a valid ${params[KEY].type}: '${VAL}'`);
if (params[KEY].type.match(re.arrayType)) {

@@ -309,8 +312,8 @@ result[params[KEY].key].push(num);

if (undefined === result[key] || !result[key].length) result[key] = arrayTypeDefaults[key];
if (undefined === result[key] || !result[key].length) {
result[key] = arrayTypeDefaults[key];
}
}
for (let key in validate) {
if (!params.hasOwnProperty(key) || undefined === result[key]) continue;
for (let key of validate) {
let help = '';

@@ -322,3 +325,3 @@ if ('function' === typeof params[key].valid) {

return conf.panic(
`The "valid" property of the "${key}" parameter must be a function or an array of valid values`
`The "valid" property of the '${key}' parameter must be a function or an array of valid values`
);

@@ -330,3 +333,3 @@ if (params[key].valid.includes(result[key])) continue;

return conf.error(
`The value provided for parameter "${key}" is not valid: "${result[key]}"` + help
`The value provided for parameter '${key}' is not valid: '${result[key]}'` + help
);

@@ -338,3 +341,3 @@ }

return conf.error(
`The parameter "${key}" is mandatory.` +
`The parameter '${key}' is mandatory.` +
(params[key].alias.length

@@ -341,0 +344,0 @@ ? ` You can also provide an alias: ${params[key].alias.join(', ')}`

@@ -37,6 +37,5 @@ export interface ArgMateParams {

allowUnknown?: boolean;
camelCaseUnknown?: boolean;
autoCamelKebabCase?: boolean;
allowNegatingFlags?: boolean;
allowKeyNumValues?: boolean;
kebabCaseAsAlias?: boolean;
intro?: IntroOutroType;

@@ -43,0 +42,0 @@ outro?: IntroOutroType;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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