tilfluktsrom/pwa/node_modules/jackspeak/dist/esm/index.min.js

33 lines
39 KiB
JavaScript
Raw Normal View History

import{inspect as q,parseArgs as yD}from"node:util";var iD=({onlyFirst:u=!1}={})=>{let t="(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";return new RegExp(t,u?void 0:"g")},FD=iD(),P=u=>u.replace(FD,""),rD=u=>{var t=u.charCodeAt(0),e=u.length==2?u.charCodeAt(1):0,D=t;return 55296<=t&&t<=56319&&56320<=e&&e<=57343&&(t&=1023,e&=1023,D=t<<10|e,D+=65536),D==12288||65281<=D&&D<=65376||65504<=D&&D<=65510?"F":D==8361||65377<=D&&D<=65470||65474<=D&&D<=65479||65482<=D&&D<=65487||65490<=D&&D<=65495||65498<=D&&D<=65500||65512<=D&&D<=65518?"H":4352<=D&&D<=4447||4515<=D&&D<=4519||4602<=D&&D<=4607||9001<=D&&D<=9002||11904<=D&&D<=11929||11931<=D&&D<=12019||12032<=D&&D<=12245||12272<=D&&D<=12283||12289<=D&&D<=12350||12353<=D&&D<=12438||12441<=D&&D<=12543||12549<=D&&D<=12589||12593<=D&&D<=12686||12688<=D&&D<=12730||12736<=D&&D<=12771||12784<=D&&D<=12830||12832<=D&&D<=12871||12880<=D&&D<=13054||13056<=D&&D<=19903||19968<=D&&D<=42124||42128<=D&&D<=42182||43360<=D&&D<=43388||44032<=D&&D<=55203||55216<=D&&D<=55238||55243<=D&&D<=55291||63744<=D&&D<=64255||65040<=D&&D<=65049||65072<=D&&D<=65106||65108<=D&&D<=65126||65128<=D&&D<=65131||110592<=D&&D<=110593||127488<=D&&D<=127490||127504<=D&&D<=127546||127552<=D&&D<=127560||127568<=D&&D<=127569||131072<=D&&D<=194367||177984<=D&&D<=196605||196608<=D&&D<=262141?"W":32<=D&&D<=126||162<=D&&D<=163||165<=D&&D<=166||D==172||D==175||10214<=D&&D<=10221||10629<=D&&D<=10630?"Na":D==161||D==164||167<=D&&D<=168||D==170||173<=D&&D<=174||176<=D&&D<=180||182<=D&&D<=186||188<=D&&D<=191||D==198||D==208||215<=D&&D<=216||222<=D&&D<=225||D==230||232<=D&&D<=234||236<=D&&D<=237||D==240||242<=D&&D<=243||247<=D&&D<=250||D==252||D==254||D==257||D==273||D==275||D==283||294<=D&&D<=295||D==299||305<=D&&D<=307||D==312||319<=D&&D<=322||D==324||328<=D&&D<=331||D==333||338<=D&&D<=339||358<=D&&D<=359||D==363||D==462||D==464||D==466||D==468||D==470||D==472||D==474||D==476||D==593||D==609||D==708||D==711||713<=D&&D<=715||D==717||D==720||728<=D&&D<=731||D==733||D==735||768<=D&&D<=879||913<=D&&D<=929||931<=D&&D<=937||945<=D&&D<=961||963<=D&&D<=969||D==1025||1040<=D&&D<=1103||D==1105||D==8208||8211<=D&&D<=8214||8216<=D&&D<=8217||8220<=D&&D<=8221||8224<=D&&D<=8226||8228<=D&&D<=8231||D==8240||8242<=D&&D<=8243||D==8245||D==8251||D==8254||D==8308||D==8319||8321<=D&&D<=8324||D==8364||D==8451||D==8453||D==8457||D==8467||D==8470||8481<=D&&D<=8482||D==8486||D==8491||8531<=D&&D<=8532||8539<=D&&D<=8542||8544<=D&&D<=8555||8560<=D&&D<=8569||D==8585||8592<=D&&D<=8601||8632<=D&&D<=8633||D==8658||D==8660||D==8679||D==8704||8706<=D&&D<=8707||8711<=D&&D<=8712||D==8715||D==8719||D==8721||D==8725||D==8730||8733<=D&&D<=8736||D==8739||D==8741||8743<=D&&D<=8748||D==8750||8756<=D&&D<=8759||8764<=D&&D<=8765||D==8776||D==8780||D==8786||8800<=D&&D<=8801||8804<=D&&D<=8807||8810<=D&&D<=8811||8814<=D&&D<=8815||8834<=D&&D<=8835||8838<=D&&D<=8839||D==8853||D==8857||D==8869||D==8895||D==8978||9312<=D&&D<=9449||9451<=D&&D<=9547||9552<=D&&D<=9587||9600<=D&&D<=9615||9618<=D&&D<=9621||9632<=D&&D<=9633||9635<=D&&D<=9641||9650<=D&&D<=9651||9654<=D&&D<=9655||9660<=D&&D<=9661||9664<=D&&D<=9665||9670<=D&&D<=9672||D==9675||9678<=D&&D<=9681||9698<=D&&D<=9701||D==9711||9733<=D&&D<=9734||D==9737||9742<=D&&D<=9743||9748<=D&&D<=9749||D==9756||D==9758||D==9792||D==9794||9824<=D&&D<=9825||9827<=D&&D<=9829||9831<=D&&D<=9834||9836<=D&&D<=9837||D==9839||9886<=D&&D<=9887||9918<=D&&D<=9919||9924<=D&&D<=9933||9935<=D&&D<=9953||D==9955||9960<=D&&D<=9983||D==10045||D==10071||10102<=D&&D<=10111||11093<=D&&D<=11097||12872<=D&&D<=12879||57344<=D&&D<=63743||65024<=D&&D<=65039||D==65533||127232<=D&&D<=127242||127248<=D&&D<=127277||127280<=D&&D<=127337||127344<=D&&D<=127386||917760<=D&&D<=917999||983040<=D&&D<=1048573||1048576<=D&&D<=1114109?"A":"N"},sD=()=>/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1
`)];for(let[C,o]of s.entries()){if(D+=o,j.has(o)){let{groups:l}=new RegExp(`(?:\\${_}(?<code>\\d+)m|\\${N}(?<uri>.*)${M})`).exec(s.slice(C).join(""))||{groups:{}};if(l.code!==void 0){let p=Number.parseFloat(l.code);n=p===aD?void 0:p}else l.uri!==void 0&&(i=l.uri.length===0?void 0:l.uri)}let E=ED.codes.get(Number(n));s[C+1]===`
`?(i&&(D+=V("")),n&&E&&(D+=R(E))):o===`
`&&(n&&E&&(D+=R(n)),i&&(D+=V(i)))}return D},BD=(u,t,e)=>String(u).normalize().replace(/\r\n/g,`
`).split(`
`).map(D=>pD(D,t,e)).join(`
`),cD={right:(u,t)=>`${" ".repeat(Math.max(0,t-h(u)))}${u}`,center:(u,t)=>`${" ".repeat(Math.max(0,t-h(u))>>1)}${u}`},fD=0,$=1,gD=2,x=3,AD=class{width;wrap;rows;constructor(u){this.width=u.width,this.wrap=u.wrap??!0,this.rows=[]}span(...u){let t=this.div(...u);t.span=!0}resetOutput(){this.rows=[]}div(...u){if(u.length===0&&this.div(""),this.wrap&&this.shouldApplyLayoutDSL(...u)&&typeof u[0]=="string")return this.applyLayoutDSL(u[0]);let t=Object.assign(u.map(e=>typeof e=="string"?this.colFromString(e):e),{span:!1});return this.rows.push(t),t}shouldApplyLayoutDSL(...u){return u.length===1&&typeof u[0]=="string"&&/[\t\n]/.test(u[0])}applyLayoutDSL(u){let t=u.split(`
`).map(n=>n.split(" ")),e=0;t.forEach(n=>{n.length>1&&h(String(n[0]))>e&&(e=Math.min(Math.floor(this.width*.5),h(String(n[0]))))}),t.forEach(n=>{this.div(...n.map((i,r)=>({text:i.trim(),padding:this.measurePadding(i),width:r===0&&n.length>1?e:void 0})))});let D=this.rows[this.rows.length-1];if(!D)throw new Error("no rows found");return D}colFromString(u){return{text:u,padding:this.measurePadding(u)}}measurePadding(u){let t=P(u),[e="",D=""]=[t.match(/\s*$/)?.[0],t.match(/^\s*/)?.[0]];return[0,e.length,0,D.length]}toString(){let u=[];return this.rows.forEach(t=>{this.rowToString(t,u)}),u.filter(t=>!t.hidden).map(t=>t.text).join(`
`)}rowToString(u,t){return this.rasterize(u).forEach((e,D)=>{let n="";e.forEach((i,r)=>{let F=u[r],{width:s}=F,C=this.negatePadding(F),o=i;if(C>h(i)&&(o+=" ".repeat(C-h(i))),F.align&&F.align!=="left"&&this.wrap){let l=cD[F.align];if(o=l(o.trim(),C),h(o)<C){let p=s||0;o+=" ".repeat(p-h(o)-1)}}let E=F.padding||[0,0,0,0];if(E[x]&&(n+=" ".repeat(E[x])),n+=Z(F,o,"| "),n+=o,n+=Z(F,o," |"),E[$]&&(n+=" ".repeat(E[$])),D===0&&t.length>0){let l=t[t.length-1];if(!l)throw new Error("last line not found");n=this.renderInline(n,l)}}),t.push({text:n.replace(/ +$/,""),span:u.span})}),t}renderInline(u,t){let e=u.match(/^ */),D=e?e[0].length:0,n=t.text,i=h(n.trimEnd());return t.span?this.wrap?D<i?u:(t.hidden=!0,n.trimEnd()+" ".repeat(D-i)+u.trimStart()):(t.hidden=!0,n+u):u}rasterize(u){let t=[],e=this.columnWidths(u),D;return u.forEach((n,i)=>{n.width=e[i],this.wrap?D=BD(n.text,this.negatePadding(n),{hard:!0}).split(`
`):D=n.text.split(`
`),n.border&&(D.unshift("."+"-".repeat(this.negatePadding(n)+2)+"."),D.push("'"+"-".repeat(this.negatePadding(n)+2)+"'")),n.padding&&(D.unshift(...new Array(n.padding[fD]||0).fill("")),D.push(...new Array(n.padding[gD]||0).fill(""))),D.forEach((r,F)=>{t[F]||t.push([]);let s=t[F]??[];for(let C=0;C<i;C++)s[C]===void 0&&s.push("");s.push(r)})}),t}negatePadding(u){let t=u.width||0;return u.padding&&(t-=(u.padding[x]||0)+(u.padding[$]||0)),u.border&&(t-=4),t}columnWidths(u){if(!this.wrap)return u.map(i=>i.width||h(i.text));let t=u.length,e=this.width,D=u.map(i=>{if(i.width)return t--,e-=i.width,i.width}),n=t?Math.floor(e/t):0;return D.map((i,r)=>{if(i===void 0){let F=u[r]??{text:"",padding:[]};return Math.max(n,mD(F))}return i})}},Z=(u,t,e)=>u.border?/[.']-+[.']/.test(t)?"":t.trim().length!==0?e:" ":"",mD=u=>{let t=u.padding||[],e=1+(t[x]||0)+(t[$]||0);return u.border?e+4:e},wD=()=>typeof process=="object"&&process.stdout&&process.stdout.columns?process.stdout.columns:80,Y=(u={})=>new AD({width:u?.width||wD(),wrap:u?.wrap});import{basename as Q}from"node:path";var uD=u=>typeof u=="string"&&(u==="string"||u==="number"||u==="boolean"),O=(u,t,e)=>e?Array.isArray(u)?!u.some(D=>!O(D,t,!1)):!1:Array.isArray(u)?!1:typeof u===t,W=(u,t)=>!!t&&(Array.isArray(u)?u.every(e=>W(e,t)):t.includes(u)),g=(u,t,e)=>!!u&&typeof u=="object"&&"type"in u&&uD(u.type)&&u.type===t&&!!u.multiple===e,b=(u,t,e)=>g(u,t,e)&&S(u.short,"string")&&S(u.description,"string")&&S(u.hint,"string")&&S(u.validate,"function")&&(u.type==="boolean"?u.validOptions===void 0:nD(u.validOptions,u.type))&&(u.default===void 0||O(u.default,t,e)),K=u=>u.type==="heading",X=u=>u.type==="description",I=Math.min(process?.stdout?.columns??80,80),J=u=>(u-1)*2,DD=(u,t)=>[u,t.replace(/[^a-zA-Z0-9]+/g," ")].join(" ").trim().toUpperCase().replace(/ /g,"_"),tD=(u,t=`
`)=>{let e=typeof u=="string"?u:typeof u=="boolean"?u?"1":"0":typeof u=="number"?String(u):Array.isArray(u)?u.map(D=>tD(D)).join(t):void 0;if(typeof e!="string")throw new Error(`could not serialize value to environment: ${JSON.stringify(u)}`,{cause:{code:"JACKSPEAK"}});return e},eD=(u,t,e,D=`
`)=>e?u?u.split(D).map(n=>eD(n,t,!1)):[]:t==="string"?u:t==="boolean"?u==="1":+u.trim(),S=(u,t)=>u===void 0||typeof u===t,nD=(u,t)=>u===void 0||Array.isArray(u)&&u.every(e=>typeof e===t),m=u=>typeof u=="string"?"string":typeof u=="boolean"?"boolean":typeof u=="number"?"number":Array.isArray(u)?`${bD([...new Set(u.map(t=>m(t)))])}[]`:`${u.type}${u.multiple?"[]":""}`,bD=u=>u.length===1&&typeof u[0]=="string"?u[0]:`(${u.join("|")})`,vD=(u,t)=>{if(t){if(u.type!==void 0&&u.type!==t.type)throw new TypeError("invalid type",{cause:{found:u.type,wanted:[t.type,void 0]}});if(u.multiple!==void 0&&!!u.multiple!==t.multiple)throw new TypeError("invalid multiple",{cause:{found:u.multiple,wanted:[t.multiple,void 0]}});return t}if(!uD(u.type))throw new TypeError("invalid type",{cause:{found:u.type,wanted:["string","number","boolean"]}});return{type:u.type,multiple:!!u.multiple}},$D=(u,t,e)=>{let D=(n,i)=>{if(!nD(i,t))throw new TypeError("invalid validOptions",{cause:{found:i,wanted:m({type:t,multiple:!0})}});if(n!==void 0&&i!==void 0&&!(Array.isArray(n)?n.every(F=>i.includes(F)):i.includes(n)))throw new TypeError("invalid default value not in validOptions",{cause:{found:n,wanted:i}})};if(u.default!==void 0&&!O(u.default,t,e))throw new TypeError("invalid default value",{cause:{found:u.default,wanted:m({type:t,multiple:e})}});if(g(u,"number",!1)||g(u,"number",!0))D(u.default,u.validOptions);else if(g(u,"string",!1)||g(u,"string",!0))D(u.default,u.validOptions);else if(g(u,"boolean",!1)||g(u,"boolean",!0)){if(u.hint!==void 0)throw new TypeError("cannot provide hint for flag");if(u.validOptions!==void 0)throw new TypeError("cannot provide validOptions for flag")}return u},xD=u=>Object.entries(u).reduce((t,[e,D])=>{let n={type:"string",multiple:!!D.multiple,...typeof D.short=="string"?{short:D.short}:void 0},i=()=>{!e.startsWith("no-")&&!u[`no-${e}`]&&(t[`no-${e}`]={type:"boolean",multiple:!!D.multiple})},r=(F,s)=>{F!==void 0&&(n.default=s(F))};return b(D,"number",!1)?r(D.default,String):b(D,"number",!0)?r(D.default,F=>F.map(s=>String(s))):b(D,"string",!1)||b(D,"string",!0)?r(D.default,F=>F):(b(D,"boolean",!1)||b(D,"boolean",!0))&&(n.type="boolean",r(D.default,F=>F),i()),t[e]=n,t},{}),z=class{#D;#e;#u;#t=[];#F;#i;#C;#r;#s;constructor(t={}){this.#u=t,this.#C=t.allowPositionals!==!1,this.#F=this.#u.env===void 0?process.env:this.#u.env,this.#i=t.envPrefix,this.#D=Object.create(null),this.#e=Object.create(null)}get definitions(){return this.#D}get shorts(){return this.#e}get jackOptions(){return this.#u}get usageFields(){return this.#t}setConfigValues(t,e=""){try{this.validate(t)}catch(D){if(e&&D instanceof Error){let n=typeof D.cause=="object"?D.cause:{};D.cause={...n,path:e},Error.captureStackTrace(D,this.setConfigValues)}throw D}for(let[D,n]of Object.entries(t)){let i=this.#D[D];if(!i)throw new Error("unexpected field in config set: "+D,{cause:{code:"JACKSPEAK",found:D}});i.default=n}return this}parse(t=process.argv){this.loadEnvDefaults();let e=this.parseRaw(t);return this.applyDefaults(e),this.writeEnv(e),e}loadEnvDefaults(){if(this.#i)for(let[t,e]of Object.entries(this.#D)){let D=DD(this.#i,t),n=this.#F[D];n!==void 0&&(e.default=eD(n,e.type,!!e.multiple,e.delim))}}applyDefaults(t){for(let[e,D]of Object.entries(this.#D))D.default!==void 0&&!(e in t.values)&&(t.values[e]=D.default)}parseRaw(t){t===process.argv&&(t=t.slice(process._eval!==void 0?1:2));let e=yD({args:t,options:xD(this.#D),strict:!1,allowPositionals:this.#C,tokens:!0}),D={values:{},positionals:[]};for(let n of e.tokens)if(n.kind==="positional"){if(D.positionals.push(n.value),this.#u.stopAtPositional||this.#u.stopAtPositionalTest?.(n.value)){D.positionals.push(...t.slice(n.index+1));break}}else if(n.kind==="option"){let i;if(n.name.startsWith("no-")){let F=this.#D[n.name],s=n.name.substring(3),C=this.#D[s];C&&C.type==="boolean"&&(!F||F.type==="boolean"&&!!F.multiple==!!C.multiple)&&(i=!1,n.name=s)}let r=this.#D[n.name];if(!r)throw new Error(`Unknown option '${n.rawName}'. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in
`)+`
`}#a(t){let e=Math.max(12,Math.min(26,Math.floor(I/3))),D=8,n,i=[];for(let r of this.#t.slice(t)){if(r.type!=="config"){n?.type==="config"&&(n.skipLine=!0),n=void 0,r.text=A(r.text,!!r.pre),i.push(r);continue}let{value:F}=r,s=F.description||"",C=F.multiple?"Can be set multiple times":"",o=F.validOptions?.length?"Valid options: "+F.validOptions.map(B=>JSON.stringify(B)).join(", "):"",E=s.includes(`
`)?`
`:`
`,l=[o,C].join(E).trim(),p=(A(s)+E+l).trim(),c=F.hint||(F.type==="number"?"n":F.type==="string"?r.name:void 0),w=F.short?F.type==="boolean"?`-${F.short} `:`-${F.short}<${c}> `:"",f=F.type==="boolean"?`${w}--${r.name}`:`${w}--${r.name}=<${c}>`,d={text:p,left:f,type:"config"};p.length>I-e&&(d.skipLine=!0),n&&f.length>e&&(n.skipLine=!0),n=d;let a=f.length+4;a>D&&a<e&&(D=a),i.push(d)}return{rows:i,maxWidth:D}}toJSON(){return Object.fromEntries(Object.entries(this.#D).map(([t,e])=>[t,{type:e.type,...e.multiple?{multiple:!0}:{},...e.delim?{delim:e.delim}:{},...e.short?{short:e.short}:{},...e.description?{description:A(e.description)}:{},...e.validate?{validate:e.validate}:{},...e.validOptions?{validOptions:e.validOptions}:{},...e.default!==void 0?{default:e.default}:{},...e.hint?{hint:e.hint}:{}}]))}[q.custom](t,e){return`Jack ${q(this.toJSON(),e)}`}},ID=(u={})=>new z(u),A=(u,t=!1)=>t?u.split(`
`).map(e=>`\u200B${e}`).join(`
`):u.split(/^\s*```\s*$/gm).map((e,D)=>{if(D%2===1){if(!e.trim())return"```\n```\n";let n=e.split(`
`);n.pop(),n.shift();let i=n.reduce((F,s)=>{let C=s.match(/^\s*/)?.[0]??"";return C.length?Math.min(C.length,F):F},1/0),r=isFinite(i)?i:0;return"\n```\n"+n.map(F=>`\u200B${F.substring(r)}`).join(`
`)+"\n```\n"}return e.replace(/([^\n])\n[ \t]*([^\n])/g,(n,i,r)=>/^[-*]/.test(r)?`${i}
${r}`:`${i} ${r}`).replace(/([^\n])[ \t]+([^\n])/g,"$1 $2").replace(/\n{3,}/g,`
`).replace(/\n[ \t]+/g,`
`).trim()}).join(`
`),v=(u,t=!1)=>{let e=A(u,t).replace(/\\/g,"\\\\");return t?`\`\`\`
${e.replace(/\u200b/g,"")}
\`\`\``:e.replace(/\n +/g,`
`).trim()},L=(u,t=!1)=>{let e=A(u,t).replace(/[\s\u200b]+/g," ").trim();return t?`\`${e}\``:e};export{z as Jack,b as isConfigOption,g as isConfigOptionOfType,uD as isConfigType,ID as jack};
//# sourceMappingURL=index.min.js.map