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

@thi.ng/args

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/args - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

1

api.js

@@ -12,2 +12,3 @@ export const DEFAULT_THEME = {

export class Tuple {
value;
constructor(value) {

@@ -14,0 +15,0 @@ this.value = value;

@@ -1,6 +0,16 @@

import { repeat } from "@thi.ng/strings";
import { repeat } from "@thi.ng/strings/repeat";
import { coerceFloat, coerceFloats, coerceHexInt, coerceHexInts, coerceInt, coerceInts, coerceJson, coerceKV, coerceOneOf, coerceTuple, } from "./coerce";
const $single = (coerce, hint) => (spec) => (Object.assign({ coerce,
hint, group: "main" }, spec));
const $multi = (coerce, hint) => (spec) => (Object.assign({ hint: $hint(hint, spec.delim), multi: true, coerce, group: "main" }, spec));
const $single = (coerce, hint) => (spec) => ({
coerce,
hint,
group: "main",
...spec,
});
const $multi = (coerce, hint) => (spec) => ({
hint: $hint(hint, spec.delim),
multi: true,
coerce,
group: "main",
...spec,
});
const $hint = (hint, delim) => hint + (delim ? `[${delim}..]` : "");

@@ -13,3 +23,8 @@ /**

*/
export const flag = (spec) => (Object.assign({ flag: true, default: false, group: "flags" }, spec));
export const flag = (spec) => ({
flag: true,
default: false,
group: "flags",
...spec,
});
/**

@@ -80,3 +95,8 @@ * Returns a full {@link ArgSpec} for a string value arg.

*/
export const json = (spec) => (Object.assign({ coerce: coerceJson, hint: "JSON", group: "main" }, spec));
export const json = (spec) => ({
coerce: coerceJson,
hint: "JSON",
group: "main",
...spec,
});
const $desc = (opts, prefix) => `${prefix ? prefix + ": " : ""}${opts.map((x) => `"${x}"`).join(", ")}`;

@@ -90,3 +110,9 @@ /**

*/
export const oneOf = (opts, spec) => (Object.assign(Object.assign({ coerce: coerceOneOf(opts), hint: "ID", group: "main" }, spec), { desc: $desc(opts, spec.desc) }));
export const oneOf = (opts, spec) => ({
coerce: coerceOneOf(opts),
hint: "ID",
group: "main",
...spec,
desc: $desc(opts, spec.desc),
});
/**

@@ -100,3 +126,10 @@ * Multi-arg version of {@link oneOf}. Returns full {@link ArgSpec} for multiple

*/
export const oneOfMulti = (opts, spec) => (Object.assign(Object.assign({ coerce: (xs) => xs.map(coerceOneOf(opts)), hint: $hint("ID", spec.delim), multi: true, group: "main" }, spec), { desc: $desc(opts, spec.desc) }));
export const oneOfMulti = (opts, spec) => ({
coerce: (xs) => xs.map(coerceOneOf(opts)),
hint: $hint("ID", spec.delim),
multi: true,
group: "main",
...spec,
desc: $desc(opts, spec.desc),
});
/**

@@ -114,3 +147,9 @@ * Returns a full {@link ArgSpec} for multiple `key=value` pair args, coerced

*/
export const kvPairs = (spec, delim = "=", strict) => (Object.assign({ coerce: coerceKV(delim, strict), hint: `key${delim}val`, multi: true, group: "main" }, spec));
export const kvPairs = (spec, delim = "=", strict) => ({
coerce: coerceKV(delim, strict),
hint: `key${delim}val`,
multi: true,
group: "main",
...spec,
});
/**

@@ -125,3 +164,9 @@ * Like {@link kvPairs}, but coerces KV pairs into a result {@link KVMultiDict}

*/
export const kvPairsMulti = (spec, delim = "=", strict) => (Object.assign({ coerce: coerceKV(delim, strict, true), hint: `key${delim}val(s)`, multi: true, group: "main" }, spec));
export const kvPairsMulti = (spec, delim = "=", strict) => ({
coerce: coerceKV(delim, strict, true),
hint: `key${delim}val(s)`,
multi: true,
group: "main",
...spec,
});
/**

@@ -153,3 +198,8 @@ * Returns a full {@link ArgSpec} for a fixed `size` tuple extracted from a

*/
export const tuple = (coerce, size, spec, delim = ",") => (Object.assign({ coerce: coerceTuple(coerce, size, delim), hint: [...repeat("N", size)].join(delim), group: "main" }, spec));
export const tuple = (coerce, size, spec, delim = ",") => ({
coerce: coerceTuple(coerce, size, delim),
hint: [...repeat("N", size)].join(delim),
group: "main",
...spec,
});
/**

@@ -156,0 +206,0 @@ * Syntax sugar for `tuple(coerceInt, size, {...}, delim)`.

129

CHANGELOG.md

@@ -6,16 +6,26 @@ # Change Log

## [1.1.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@1.1.0...@thi.ng/args@1.1.1) (2021-09-03)
# [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@1.1.1...@thi.ng/args@2.0.0) (2021-10-12)
**Note:** Version bump only for package @thi.ng/args
### Build System
* major update of ALL pkgs (export maps, ESM only) ([0d1d6ea](https://github.com/thi-ng/umbrella/commit/0d1d6ea9fab2a645d6c5f2bf2591459b939c09b6))
### BREAKING CHANGES
# [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@1.0.4...@thi.ng/args@1.1.0) (2021-08-19)
* discontinue CommonJS & UMD versions
- only ESM modules will be published from now on
- CJS obsolete due to ESM support in recent versions of node:
- i.e. launch NodeJS via:
- `node --experimental-specifier-resolution=node --experimental-repl-await`
- in the node REPL use `await import(...)` instead of `require()`
- UMD obsolete due to widespread browser support for ESM
### Features
Also:
- normalize/restructure/reorg all package.json files
- cleanup all build scripts, remove obsolete
- switch from mocha to @thi.ng/testament for all tests
* **args:** capitalize usage section headings ([eaa0f23](https://github.com/thi-ng/umbrella/commit/eaa0f23a88cfb98da05b245b720a6fbb260ea7da))

@@ -26,102 +36,67 @@

## [0.7.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.7.0...@thi.ng/args@0.7.1) (2021-07-29)
# [1.1.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@1.0.4...@thi.ng/args@1.1.0) (2021-08-19)
### Features
### Bug Fixes
- **args:** capitalize usage section headings ([eaa0f23](https://github.com/thi-ng/umbrella/commit/eaa0f23a88cfb98da05b245b720a6fbb260ea7da))
* **args:** omit empty groups from usage() ([a66c19a](https://github.com/thi-ng/umbrella/commit/a66c19aa8d682a7f4b6ae5b3de51a26e806a02dc))
## [0.7.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.7.0...@thi.ng/args@0.7.1) (2021-07-29)
### Bug Fixes
- **args:** omit empty groups from usage() ([a66c19a](https://github.com/thi-ng/umbrella/commit/a66c19aa8d682a7f4b6ae5b3de51a26e806a02dc))
# [0.7.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.6.0...@thi.ng/args@0.7.0) (2021-07-01)
### Features
# [0.7.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.6.0...@thi.ng/args@0.7.0) (2021-07-01)
- **args:** add showGroupNames option ([6917111](https://github.com/thi-ng/umbrella/commit/6917111aa6f019cbc4622a30be65c7f43cf995f9))
# [0.6.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.5.1...@thi.ng/args@0.6.0) (2021-06-08)
### Features
### Features
* **args:** add showGroupNames option ([6917111](https://github.com/thi-ng/umbrella/commit/6917111aa6f019cbc4622a30be65c7f43cf995f9))
- **args:** add kvPairsMulti(), update coerceKV() ([fd12f80](https://github.com/thi-ng/umbrella/commit/fd12f807dba2546133278a607c4b79dcf9a12b07))
# [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.4.2...@thi.ng/args@0.5.0) (2021-03-28)
### Features
- **args:** add vec() arg type ([f05cb2a](https://github.com/thi-ng/umbrella/commit/f05cb2a6d0798ef0558775a81dba2d834308747c))
- **args:** wordwrap usage prefix/suffix, defaults ([325b558](https://github.com/thi-ng/umbrella/commit/325b558f74f8dbfaa2c7de72c6800cdbc8c54acd))
# [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.3.1...@thi.ng/args@0.4.0) (2021-03-22)
# [0.6.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.5.1...@thi.ng/args@0.6.0) (2021-06-08)
### Features
- **args:** add arg groups, segment usage output ([ebf5197](https://github.com/thi-ng/umbrella/commit/ebf51974e4e1e1d5288af9ad420d4211addd95ad))
- **args:** support arbitrary length aliases ([1cfdf49](https://github.com/thi-ng/umbrella/commit/1cfdf49a53cca2f80836caf428e220e90f687ad1))
### Features
## [0.3.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.3.0...@thi.ng/args@0.3.1) (2021-03-21)
* **args:** add kvPairsMulti(), update coerceKV() ([fd12f80](https://github.com/thi-ng/umbrella/commit/fd12f807dba2546133278a607c4b79dcf9a12b07))
### Bug Fixes
- **args:** fix usage() show defaults logic ([ae31158](https://github.com/thi-ng/umbrella/commit/ae31158c9496d7c116ee2b4a22ca843888d2bddd))
# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.2.7...@thi.ng/args@0.3.0) (2021-03-20)
### Features
- **args:** update ParseOpts, UsageOpts ([6577c80](https://github.com/thi-ng/umbrella/commit/6577c806e246ecf8244b1af6a2cefc400a7eb365))
# [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.4.2...@thi.ng/args@0.5.0) (2021-03-28)
# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.1.0...@thi.ng/args@0.2.0) (2021-01-13)
### Features
### Features
- **args:** add defaultHint opt, update usage() ([f8a4146](https://github.com/thi-ng/umbrella/commit/f8a414605a0d5c93fcef83ab931911c6c2f39f7d))
* **args:** add vec() arg type ([f05cb2a](https://github.com/thi-ng/umbrella/commit/f05cb2a6d0798ef0558775a81dba2d834308747c))
* **args:** wordwrap usage prefix/suffix, defaults ([325b558](https://github.com/thi-ng/umbrella/commit/325b558f74f8dbfaa2c7de72c6800cdbc8c54acd))
# 0.1.0 (2021-01-10)
### Features
# [0.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.3.1...@thi.ng/args@0.4.0) (2021-03-22)
### Features
* **args:** add arg groups, segment usage output ([ebf5197](https://github.com/thi-ng/umbrella/commit/ebf51974e4e1e1d5288af9ad420d4211addd95ad))
* **args:** support arbitrary length aliases ([1cfdf49](https://github.com/thi-ng/umbrella/commit/1cfdf49a53cca2f80836caf428e220e90f687ad1))
## [0.3.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.3.0...@thi.ng/args@0.3.1) (2021-03-21)
### Bug Fixes
* **args:** fix usage() show defaults logic ([ae31158](https://github.com/thi-ng/umbrella/commit/ae31158c9496d7c116ee2b4a22ca843888d2bddd))
# [0.3.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.2.7...@thi.ng/args@0.3.0) (2021-03-20)
### Features
* **args:** update ParseOpts, UsageOpts ([6577c80](https://github.com/thi-ng/umbrella/commit/6577c806e246ecf8244b1af6a2cefc400a7eb365))
# [0.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.1.0...@thi.ng/args@0.2.0) (2021-01-13)
### Features
* **args:** add defaultHint opt, update usage() ([f8a4146](https://github.com/thi-ng/umbrella/commit/f8a414605a0d5c93fcef83ab931911c6c2f39f7d))
# 0.1.0 (2021-01-10)
### Features
* **args:** add kv args, callbacks, usage opts ([c306aba](https://github.com/thi-ng/umbrella/commit/c306abac31dc03bb15a19c36192ee5c07afa1063))
* **args:** add strict mode kvArgs()/coerceKV(), add docs ([b76c4f1](https://github.com/thi-ng/umbrella/commit/b76c4f11ddbe3b7c1a195a93ceed3a953666ef5d))
* **args:** add tuple arg type support ([a05dde9](https://github.com/thi-ng/umbrella/commit/a05dde957be54ae7ed6aeab8233bff0d8573c675))
* **args:** import as new package ([af5d943](https://github.com/thi-ng/umbrella/commit/af5d943153b3012be04ed0e9a044ee944465d035))
* **args:** major general package update ([26ec49a](https://github.com/thi-ng/umbrella/commit/26ec49afc0fa389b7a2551b116a85d95df4aaeee))
* **args:** update multi arg specs, parse ([dbdf913](https://github.com/thi-ng/umbrella/commit/dbdf913b4ed730c2c07246c24ecbafb32d9dc37e))
- **args:** add kv args, callbacks, usage opts ([c306aba](https://github.com/thi-ng/umbrella/commit/c306abac31dc03bb15a19c36192ee5c07afa1063))
- **args:** add strict mode kvArgs()/coerceKV(), add docs ([b76c4f1](https://github.com/thi-ng/umbrella/commit/b76c4f11ddbe3b7c1a195a93ceed3a953666ef5d))
- **args:** add tuple arg type support ([a05dde9](https://github.com/thi-ng/umbrella/commit/a05dde957be54ae7ed6aeab8233bff0d8573c675))
- **args:** import as new package ([af5d943](https://github.com/thi-ng/umbrella/commit/af5d943153b3012be04ed0e9a044ee944465d035))
- **args:** major general package update ([26ec49a](https://github.com/thi-ng/umbrella/commit/26ec49afc0fa389b7a2551b116a85d95df4aaeee))
- **args:** update multi arg specs, parse ([dbdf913](https://github.com/thi-ng/umbrella/commit/dbdf913b4ed730c2c07246c24ecbafb32d9dc37e))

@@ -1,3 +0,4 @@

import { isHex, isNumericFloat, isNumericInt } from "@thi.ng/checks";
import { illegalArgs } from "@thi.ng/errors";
import { isHex } from "@thi.ng/checks/is-hex";
import { isNumericFloat, isNumericInt } from "@thi.ng/checks/is-numeric";
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
import { Tuple } from "./api";

@@ -4,0 +5,0 @@ export const coerceString = (x) => x;

{
"name": "@thi.ng/args",
"version": "1.1.1",
"version": "2.0.0",
"description": "Declarative, functional & typechecked CLI argument/options parser, value coercions etc.",
"type": "module",
"module": "./index.js",
"main": "./lib/index.js",
"umd:main": "./lib/index.umd.js",
"typings": "./index.d.ts",
"sideEffects": false,
"repository": {

@@ -27,26 +27,20 @@ "type": "git",

"scripts": {
"build": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module",
"build:release": "yarn clean && yarn build:es6 && node ../../scripts/bundle-module all",
"build:es6": "tsc --declaration",
"build:test": "rimraf build && tsc -p test/tsconfig.json",
"build:check": "tsc --isolatedModules --noEmit",
"test": "mocha test",
"cover": "nyc mocha test && nyc report --reporter=lcov",
"clean": "rimraf *.js *.d.ts *.map .nyc_output build coverage doc lib",
"doc:readme": "ts-node -P ../../tools/tsconfig.json ../../tools/src/readme.ts",
"build": "yarn clean && tsc --declaration",
"clean": "rimraf *.js *.d.ts *.map doc",
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
"doc:ae": "mkdir -p .ae/doc .ae/temp && node_modules/.bin/api-extractor run --local --verbose",
"doc": "typedoc --excludePrivate --out doc --theme ../../tools/doc/typedoc-theme src/index.ts",
"pub": "yarn build:release && yarn publish --access public"
"doc:readme": "yarn doc:stats && ../../scripts/node-esm ../../tools/src/readme.ts",
"doc:stats": "../../scripts/node-esm ../../tools/src/module-stats.ts",
"pub": "yarn build && yarn publish --access public",
"test": "testament test"
},
"dependencies": {
"@thi.ng/api": "^7.2.0",
"@thi.ng/checks": "^2.9.11",
"@thi.ng/errors": "^1.3.4",
"@thi.ng/strings": "^2.1.7"
"@thi.ng/api": "^8.0.0",
"@thi.ng/checks": "^3.0.0",
"@thi.ng/errors": "^2.0.0",
"@thi.ng/strings": "^3.0.0"
},
"files": [
"*.js",
"*.d.ts",
"lib"
],
"devDependencies": {
"@thi.ng/testament": "^0.1.0"
},
"keywords": [

@@ -71,7 +65,30 @@ "argument",

},
"sideEffects": false,
"files": [
"*.js",
"*.d.ts"
],
"exports": {
".": {
"import": "./index.js"
},
"./api": {
"import": "./api.js"
},
"./args": {
"import": "./args.js"
},
"./coerce": {
"import": "./coerce.js"
},
"./parse": {
"import": "./parse.js"
},
"./usage": {
"import": "./usage.js"
}
},
"thi.ng": {
"year": 2018
},
"gitHead": "d971cb3f9b215a95483f78f1a8614015e331146f"
"gitHead": "9ac1344b38b565eb894306fbf72233b6c0b2d115"
}

@@ -1,7 +0,7 @@

import { isArray } from "@thi.ng/checks";
import { illegalArgs } from "@thi.ng/errors";
import { camel } from "@thi.ng/strings";
import { isArray } from "@thi.ng/checks/is-array";
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
import { camel } from "@thi.ng/strings/case";
import { usage } from "./usage";
export const parse = (specs, argv, opts) => {
opts = Object.assign({ start: 2, showUsage: true, help: ["--help", "-h"] }, opts);
opts = { start: 2, showUsage: true, help: ["--help", "-h"], ...opts };
try {

@@ -8,0 +8,0 @@ return parseOpts(specs, argv, opts);

@@ -57,11 +57,19 @@ <!-- This file is generated - DO NOT EDIT! -->

ES module import:
```html
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/args?module" crossorigin></script>
<script type="module" src="https://cdn.skypack.dev/@thi.ng/args"></script>
```
// UMD
<script src="https://unpkg.com/@thi.ng/args/lib/index.umd.js" crossorigin></script>
[Skypack documentation](https://docs.skypack.dev/)
For NodeJS (v14.6+):
```text
node --experimental-specifier-resolution=node --experimental-repl-await
> const args = await import("@thi.ng/args");
```
Package sizes (gzipped, pre-treeshake): ESM: 2.40 KB / CJS: 2.53 KB / UMD: 2.44 KB
Package sizes (gzipped, pre-treeshake): ESM: 2.45 KB

@@ -68,0 +76,0 @@ ## Dependencies

@@ -1,7 +0,21 @@

import { capitalize, kebab, lengthAnsi, padRight, repeat, SPLIT_ANSI, stringify, wordWrapLines, } from "@thi.ng/strings";
import { lengthAnsi } from "@thi.ng/strings/ansi";
import { capitalize, kebab } from "@thi.ng/strings/case";
import { padRight } from "@thi.ng/strings/pad-right";
import { repeat } from "@thi.ng/strings/repeat";
import { stringify } from "@thi.ng/strings/stringify";
import { SPLIT_ANSI, wordWrapLines } from "@thi.ng/strings/word-wrap";
import { DEFAULT_THEME } from "./api";
export const usage = (specs, opts = {}) => {
opts = Object.assign({ lineWidth: 80, paramWidth: 32, showDefaults: true, prefix: "", suffix: "", groups: ["flags", "main"] }, opts);
opts = {
lineWidth: 80,
paramWidth: 32,
showDefaults: true,
prefix: "",
suffix: "",
groups: ["flags", "main"],
...opts,
};
const theme = opts.color !== false
? Object.assign(Object.assign({}, DEFAULT_THEME), opts.color) : {};
? { ...DEFAULT_THEME, ...opts.color }
: {};
const indent = repeat(" ", opts.paramWidth);

@@ -8,0 +22,0 @@ const format = (ids) => ids.map((id) => argUsage(id, specs[id], opts, theme, indent));

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