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.4.0 to 0.4.1

8

CHANGELOG.md

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

## [0.4.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.4.0...@thi.ng/args@0.4.1) (2021-03-24)
**Note:** Version bump only for package @thi.ng/args
# [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)

@@ -8,0 +16,0 @@

10

lib/index.js

@@ -100,5 +100,9 @@ 'use strict';

: "";
return (strings$1.padRight(opts.paramWidth)(params, strings$1.stripAnsi(params).length) +
strings$1.wordWrapLines(prefix + (spec.desc || "") + defaults, opts.lineWidth - opts.paramWidth)
.map((l, i) => (i > 0 ? indent : "") + l)
return (strings$1.padRight(opts.paramWidth)(params, strings$1.lengthAnsi(params)) +
strings$1.wordWrapLines(prefix + (spec.desc || "") + defaults, {
width: opts.lineWidth - opts.paramWidth,
splitter: strings$1.SPLIT_ANSI,
hard: true,
})
.map((l, i) => (i > 0 ? indent + l : l))
.join("\n"));

@@ -105,0 +109,0 @@ });

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

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

"@thi.ng/errors": "^1.3.0",
"@thi.ng/strings": "^1.15.6"
"@thi.ng/strings": "^2.0.0"
},

@@ -87,3 +87,3 @@ "files": [

},
"gitHead": "feb86e519d19f661b6db6f2adb3a54f6e1e55f80"
"gitHead": "88f03faab663d8cb36f83712249ef80cb16739c5"
}

@@ -64,3 +64,3 @@ <!-- This file is generated - DO NOT EDIT! -->

Package sizes (gzipped, pre-treeshake): ESM: 2.14 KB / CJS: 2.27 KB / UMD: 2.23 KB
Package sizes (gzipped, pre-treeshake): ESM: 2.17 KB / CJS: 2.29 KB / UMD: 2.25 KB

@@ -67,0 +67,0 @@ ## Dependencies

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

import { kebab, padRight, repeat, stringify, stripAnsi, wordWrapLines, } from "@thi.ng/strings";
import { kebab, lengthAnsi, padRight, repeat, SPLIT_ANSI, stringify, wordWrapLines, } from "@thi.ng/strings";
import { DEFAULT_THEME } from "./api";

@@ -29,5 +29,9 @@ export const usage = (specs, opts = {}) => {

: "";
return (padRight(opts.paramWidth)(params, stripAnsi(params).length) +
wordWrapLines(prefix + (spec.desc || "") + defaults, opts.lineWidth - opts.paramWidth)
.map((l, i) => (i > 0 ? indent : "") + l)
return (padRight(opts.paramWidth)(params, lengthAnsi(params)) +
wordWrapLines(prefix + (spec.desc || "") + defaults, {
width: opts.lineWidth - opts.paramWidth,
splitter: SPLIT_ANSI,
hard: true,
})
.map((l, i) => (i > 0 ? indent + l : l))
.join("\n"));

@@ -34,0 +38,0 @@ });

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