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 0.7.0 to 0.7.1

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [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)

@@ -8,0 +19,0 @@

4

lib/index.js

@@ -122,6 +122,8 @@ 'use strict';

const groups = opts.groups
? opts.groups.map((gid) => [
? opts.groups
.map((gid) => [
gid,
sortedIDs.filter((id) => specs[id].group === gid),
])
.filter((g) => !!g[1].length)
: [["options", sortedIDs]];

@@ -128,0 +130,0 @@ return [

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/strings"),require("@thi.ng/checks"),require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/strings","@thi.ng/checks","@thi.ng/errors"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.args={}),e.thi.ng.strings,e.thi.ng.checks,e.thi.ng.errors)}(this,(function(e,t,i,s){"use strict";const n={default:95,hint:90,multi:90,param:96,required:33};class r{constructor(e){this.value=e}deref(){return this.value}}const a=e=>i.isNumericFloat(e)?parseFloat(e):s.illegalArgs(`not a numeric value: ${e}`),l=e=>e.map(a),o=e=>i.isHex(e)?parseInt(e,16):s.illegalArgs(`not a hex value: ${e}`),c=e=>e.map(o),u=e=>i.isNumericInt(e)?parseInt(e):s.illegalArgs(`not an integer: ${e}`),g=e=>e.map(u),p=e=>JSON.parse(e),h=e=>t=>e.includes(t)?t:s.illegalArgs(`invalid option: ${t}`);function d(e="=",t=!1,i=!1){return n=>n.reduce(((n,r)=>{const a=r.indexOf(e);if(t&&a<1&&s.illegalArgs(`got '${r}', but expected a 'key${e}value' pair`),a>0){const e=r.substr(0,a),t=r.substr(a+1);i?n[e]?n[e].push(t):n[e]=[t]:n[e]=t}else n[r]=i?["true"]:"true";return n}),{})}const f=(e,t,i=",")=>n=>{const a=n.split(i);return a.length!==t&&s.illegalArgs(`got '${n}', but expected a tuple of ${t} values`),new r(a.map(e))},m=(e,t)=>i=>Object.assign({coerce:e,hint:t,group:"main"},i),b=(e,t)=>i=>Object.assign({hint:$(t,i.delim),multi:!0,coerce:e,group:"main"},i),$=(e,t)=>e+(t?`[${t}..]`:""),O=m((e=>e),"STR"),j=b((e=>e),"STR"),v=m(a,"NUM"),x=m(o,"HEX"),A=m(u,"INT"),k=b(l,"NUM"),y=b(c,"HEX"),I=b(g,"INT"),w=(e,t)=>`${t?t+": ":""}${e.map((e=>`"${e}"`)).join(", ")}`,N=(e,i,s,n=",")=>Object.assign({coerce:f(e,i,n),hint:[...t.repeat("N",i)].join(n),group:"main"},s),T=(e,i={})=>{const s=!1!==(i=Object.assign({lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"]},i)).color?Object.assign(Object.assign({},n),i.color):{},r=t.repeat(" ",i.paramWidth),a=n=>n.map((n=>{const a=e[n],l=a.hint?W(" "+a.hint,s.hint):"",o=W(`--${t.kebab(n)}`,s.param),c=`${a.alias?`${W("-"+a.alias,s.param)}${l}, `:""}${o}${l}`,u=!1===a.optional&&void 0===a.default,g=[];u&&g.push("required"),a.multi&&g.push("multiple");const p=g.length?W(`[${g.join(", ")}] `,u?s.required:s.multi):"",h=i.showDefaults&&null!=a.default&&!1!==a.default?W(` (default: ${t.stringify(!0)(null!=a.defaultHint?a.defaultHint:a.default)})`,s.default):"";return t.padRight(i.paramWidth)(c,t.lengthAnsi(c))+H(p+(a.desc||"")+h,i.lineWidth-i.paramWidth).map(((e,t)=>t>0?r+e:e)).join("\n")})),l=Object.keys(e).sort(),o=i.groups?i.groups.map((t=>[t,l.filter((i=>e[i].group===t))])):[["options",l]];return[...H(i.prefix,i.lineWidth),...o.map((([e,t])=>[...i.showGroupNames?[`${e}:\n`]:[],...a(t),""].join("\n"))),...H(i.suffix,i.lineWidth)].join("\n")},W=(e,t)=>null!=t?`[${t}m${e}`:e,H=(e,i)=>e?t.wordWrapLines(e,{width:i,splitter:t.SPLIT_ANSI,hard:!0}):[],S=(e,t,i)=>{const n=q(e),r={};let a,l,o=i.start;for(;o<t.length;){const s=t[o];if(a){if(M(l,r,a,s))break;a=null,o++}else{if(i.help.includes(s))return void console.log(T(e,i.usageOpts));const t=E(e,n,r,s);if(a=t.id,l=t.spec,o+=~~(t.state<2),t.state)break}}return a&&s.illegalArgs(`missing value for: --${a}`),{result:D(e,r),index:o,rest:t.slice(o),done:o>=t.length}},q=e=>Object.entries(e).reduce(((e,[t,i])=>i.alias?(e[i.alias]=t,e):e),{}),E=(e,i,n,r)=>{if("-"===r[0]){let a;if("-"===r[1]){if("--"===r)return{state:1};a=t.camel(r.substr(2))}else a=i[r.substr(1)],!a&&s.illegalArgs(`unknown option: ${r}`);const l=e[a];return!l&&s.illegalArgs(a),l.flag&&(n[a]=!0,a=void 0,l.fn&&!l.fn("true"))?{state:1,spec:l}:{state:0,id:a,spec:l}}return{state:2}},M=(e,t,n,r)=>(/^-[a-z]/i.test(r)&&s.illegalArgs(`missing value for: --${n}`),e.multi?i.isArray(t[n])?t[n].push(r):t[n]=[r]:t[n]=r,e.fn&&!e.fn(r)),D=(e,t)=>{let i;for(let n in e)i=e[n],void 0===t[n]?void 0!==i.default?t[n]=i.default:!1===i.optional&&s.illegalArgs(`missing arg: --${n}`):i.coerce&&F(i,t,n);return t},F=(e,t,i)=>{try{e.multi&&e.delim&&(t[i]=t[i].reduce(((t,i)=>(t.push(...i.split(e.delim)),t)),[])),t[i]=e.coerce(t[i])}catch(e){throw new Error(`arg --${i}: ${e.message}`)}};e.DEFAULT_THEME=n,e.Tuple=r,e.coerceFloat=a,e.coerceFloats=l,e.coerceHexInt=o,e.coerceHexInts=c,e.coerceInt=u,e.coerceInts=g,e.coerceJson=p,e.coerceKV=d,e.coerceOneOf=h,e.coerceString=e=>e,e.coerceTuple=f,e.flag=e=>Object.assign({flag:!0,default:!1,group:"flags"},e),e.float=v,e.floats=k,e.hex=x,e.hexes=y,e.int=A,e.ints=I,e.json=e=>Object.assign({coerce:p,hint:"JSON",group:"main"},e),e.kvPairs=(e,t="=",i)=>Object.assign({coerce:d(t,i),hint:`key${t}val`,multi:!0,group:"main"},e),e.kvPairsMulti=(e,t="=",i)=>Object.assign({coerce:d(t,i,!0),hint:`key${t}val(s)`,multi:!0,group:"main"},e),e.oneOf=(e,t)=>Object.assign(Object.assign({coerce:h(e),hint:"ID",group:"main"},t),{desc:w(e,t.desc)}),e.oneOfMulti=(e,t)=>Object.assign(Object.assign({coerce:t=>t.map(h(e)),hint:$("ID",t.delim),multi:!0,group:"main"},t),{desc:w(e,t.desc)}),e.parse=(e,t,i)=>{i=Object.assign({start:2,showUsage:!0,help:["--help","-h"]},i);try{return S(e,t,i)}catch(t){throw i.showUsage&&console.log(t.message+"\n\n"+T(e,i.usageOpts)),t}},e.size=(e,t,i="x")=>N(u,e,t,i),e.string=O,e.strings=j,e.tuple=N,e.usage=T,e.vec=(e,t,i=",")=>N(a,e,t,i),Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/strings"),require("@thi.ng/checks"),require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/strings","@thi.ng/checks","@thi.ng/errors"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.args={}),e.thi.ng.strings,e.thi.ng.checks,e.thi.ng.errors)}(this,(function(e,t,i,s){"use strict";const n={default:95,hint:90,multi:90,param:96,required:33};class r{constructor(e){this.value=e}deref(){return this.value}}const a=e=>i.isNumericFloat(e)?parseFloat(e):s.illegalArgs(`not a numeric value: ${e}`),l=e=>e.map(a),o=e=>i.isHex(e)?parseInt(e,16):s.illegalArgs(`not a hex value: ${e}`),c=e=>e.map(o),u=e=>i.isNumericInt(e)?parseInt(e):s.illegalArgs(`not an integer: ${e}`),g=e=>e.map(u),p=e=>JSON.parse(e),h=e=>t=>e.includes(t)?t:s.illegalArgs(`invalid option: ${t}`);function f(e="=",t=!1,i=!1){return n=>n.reduce(((n,r)=>{const a=r.indexOf(e);if(t&&a<1&&s.illegalArgs(`got '${r}', but expected a 'key${e}value' pair`),a>0){const e=r.substr(0,a),t=r.substr(a+1);i?n[e]?n[e].push(t):n[e]=[t]:n[e]=t}else n[r]=i?["true"]:"true";return n}),{})}const d=(e,t,i=",")=>n=>{const a=n.split(i);return a.length!==t&&s.illegalArgs(`got '${n}', but expected a tuple of ${t} values`),new r(a.map(e))},m=(e,t)=>i=>Object.assign({coerce:e,hint:t,group:"main"},i),b=(e,t)=>i=>Object.assign({hint:$(t,i.delim),multi:!0,coerce:e,group:"main"},i),$=(e,t)=>e+(t?`[${t}..]`:""),O=m((e=>e),"STR"),j=b((e=>e),"STR"),v=m(a,"NUM"),x=m(o,"HEX"),A=m(u,"INT"),k=b(l,"NUM"),y=b(c,"HEX"),I=b(g,"INT"),w=(e,t)=>`${t?t+": ":""}${e.map((e=>`"${e}"`)).join(", ")}`,N=(e,i,s,n=",")=>Object.assign({coerce:d(e,i,n),hint:[...t.repeat("N",i)].join(n),group:"main"},s),T=(e,i={})=>{const s=!1!==(i=Object.assign({lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"]},i)).color?Object.assign(Object.assign({},n),i.color):{},r=t.repeat(" ",i.paramWidth),a=n=>n.map((n=>{const a=e[n],l=a.hint?W(" "+a.hint,s.hint):"",o=W(`--${t.kebab(n)}`,s.param),c=`${a.alias?`${W("-"+a.alias,s.param)}${l}, `:""}${o}${l}`,u=!1===a.optional&&void 0===a.default,g=[];u&&g.push("required"),a.multi&&g.push("multiple");const p=g.length?W(`[${g.join(", ")}] `,u?s.required:s.multi):"",h=i.showDefaults&&null!=a.default&&!1!==a.default?W(` (default: ${t.stringify(!0)(null!=a.defaultHint?a.defaultHint:a.default)})`,s.default):"";return t.padRight(i.paramWidth)(c,t.lengthAnsi(c))+H(p+(a.desc||"")+h,i.lineWidth-i.paramWidth).map(((e,t)=>t>0?r+e:e)).join("\n")})),l=Object.keys(e).sort(),o=i.groups?i.groups.map((t=>[t,l.filter((i=>e[i].group===t))])).filter((e=>!!e[1].length)):[["options",l]];return[...H(i.prefix,i.lineWidth),...o.map((([e,t])=>[...i.showGroupNames?[`${e}:\n`]:[],...a(t),""].join("\n"))),...H(i.suffix,i.lineWidth)].join("\n")},W=(e,t)=>null!=t?`[${t}m${e}`:e,H=(e,i)=>e?t.wordWrapLines(e,{width:i,splitter:t.SPLIT_ANSI,hard:!0}):[],S=(e,t,i)=>{const n=q(e),r={};let a,l,o=i.start;for(;o<t.length;){const s=t[o];if(a){if(M(l,r,a,s))break;a=null,o++}else{if(i.help.includes(s))return void console.log(T(e,i.usageOpts));const t=E(e,n,r,s);if(a=t.id,l=t.spec,o+=~~(t.state<2),t.state)break}}return a&&s.illegalArgs(`missing value for: --${a}`),{result:D(e,r),index:o,rest:t.slice(o),done:o>=t.length}},q=e=>Object.entries(e).reduce(((e,[t,i])=>i.alias?(e[i.alias]=t,e):e),{}),E=(e,i,n,r)=>{if("-"===r[0]){let a;if("-"===r[1]){if("--"===r)return{state:1};a=t.camel(r.substr(2))}else a=i[r.substr(1)],!a&&s.illegalArgs(`unknown option: ${r}`);const l=e[a];return!l&&s.illegalArgs(a),l.flag&&(n[a]=!0,a=void 0,l.fn&&!l.fn("true"))?{state:1,spec:l}:{state:0,id:a,spec:l}}return{state:2}},M=(e,t,n,r)=>(/^-[a-z]/i.test(r)&&s.illegalArgs(`missing value for: --${n}`),e.multi?i.isArray(t[n])?t[n].push(r):t[n]=[r]:t[n]=r,e.fn&&!e.fn(r)),D=(e,t)=>{let i;for(let n in e)i=e[n],void 0===t[n]?void 0!==i.default?t[n]=i.default:!1===i.optional&&s.illegalArgs(`missing arg: --${n}`):i.coerce&&F(i,t,n);return t},F=(e,t,i)=>{try{e.multi&&e.delim&&(t[i]=t[i].reduce(((t,i)=>(t.push(...i.split(e.delim)),t)),[])),t[i]=e.coerce(t[i])}catch(e){throw new Error(`arg --${i}: ${e.message}`)}};e.DEFAULT_THEME=n,e.Tuple=r,e.coerceFloat=a,e.coerceFloats=l,e.coerceHexInt=o,e.coerceHexInts=c,e.coerceInt=u,e.coerceInts=g,e.coerceJson=p,e.coerceKV=f,e.coerceOneOf=h,e.coerceString=e=>e,e.coerceTuple=d,e.flag=e=>Object.assign({flag:!0,default:!1,group:"flags"},e),e.float=v,e.floats=k,e.hex=x,e.hexes=y,e.int=A,e.ints=I,e.json=e=>Object.assign({coerce:p,hint:"JSON",group:"main"},e),e.kvPairs=(e,t="=",i)=>Object.assign({coerce:f(t,i),hint:`key${t}val`,multi:!0,group:"main"},e),e.kvPairsMulti=(e,t="=",i)=>Object.assign({coerce:f(t,i,!0),hint:`key${t}val(s)`,multi:!0,group:"main"},e),e.oneOf=(e,t)=>Object.assign(Object.assign({coerce:h(e),hint:"ID",group:"main"},t),{desc:w(e,t.desc)}),e.oneOfMulti=(e,t)=>Object.assign(Object.assign({coerce:t=>t.map(h(e)),hint:$("ID",t.delim),multi:!0,group:"main"},t),{desc:w(e,t.desc)}),e.parse=(e,t,i)=>{i=Object.assign({start:2,showUsage:!0,help:["--help","-h"]},i);try{return S(e,t,i)}catch(t){throw i.showUsage&&console.log(t.message+"\n\n"+T(e,i.usageOpts)),t}},e.size=(e,t,i="x")=>N(u,e,t,i),e.string=O,e.strings=j,e.tuple=N,e.usage=T,e.vec=(e,t,i=",")=>N(a,e,t,i),Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@thi.ng/args",
"version": "0.7.0",
"version": "0.7.1",
"description": "Declarative, functional & typechecked CLI argument/options parser, value coercions etc.",

@@ -75,3 +75,3 @@ "module": "./index.js",

},
"gitHead": "a3dadf7acedcca6a15a7e6d655c923b16e2ededa"
"gitHead": "2c0a80e5c455fe9f302548e16b4eedbc62cacc73"
}

@@ -37,6 +37,8 @@ import { kebab, lengthAnsi, padRight, repeat, SPLIT_ANSI, stringify, wordWrapLines, } from "@thi.ng/strings";

const groups = opts.groups
? opts.groups.map((gid) => [
? opts.groups
.map((gid) => [
gid,
sortedIDs.filter((id) => specs[id].group === gid),
])
.filter((g) => !!g[1].length)
: [["options", sortedIDs]];

@@ -43,0 +45,0 @@ return [

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