@homedev/framework 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -636,7 +636,7 @@ declare global {
|
|
|
636
636
|
var defined: <T>(value: T | undefined | null, msg?: string) => T;
|
|
637
637
|
var createAsyncFunction: (body: string, args?: Record<string, any>, thisArg?: any) => AsyncFunction;
|
|
638
638
|
var runAsyncFunction: <T = void>(options: RunAsyncFunctionOptions) => Promise<T>;
|
|
639
|
-
|
|
639
|
+
type AsyncEmitter<T extends object> = AsyncEmitterClass<T>;
|
|
640
640
|
}
|
|
641
641
|
|
|
642
642
|
declare global {
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Array.prototype.findOrFail=function(T,U,O){let K=this.find(T,O);if(K===void 0)throw Error(U??"Element not found");return K};Array.flat=function(T){if(Array.isArray(T))return T.flat(2);else return[T]};Array.prototype.forEachAsync=async function(T){for(let U=0;U<this.length;U++)await T(this[U],U,this)};Array.prototype.groupBy=function(T){return this.reduce((U,O)=>{let K=T(O);if(!U[K])U[K]=[];return U[K].push(O),U},{})};Array.prototype.createInstances=function(T,...U){return this.map((O,K)=>new T(...U,O,K))};Array.prototype.mapAsync=async function(T){return Promise.all(this.map(T))};Array.prototype.nonNullMap=function(T){let U=[];for(let O=0;O<this.length;O++){let K=T(this[O],O,this);if(K!=null)U.push(K)}return U};Array.prototype.nonNullMapAsync=async function(T){let U=[];for(let O=0;O<this.length;O++){let K=await T(this[O],O,this);if(K!=null)U.push(K)}return U};Array.prototype.mergeAll=function(T){let U={};for(let O of this.slice().reverse())Object.merge(O,U,T);return U};Array.prototype.toObject=function(T,U){return Object.fromEntries(this.map((O)=>{let K=T(O),X=U?U(O):O;return[K,X]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((U)=>[String(U[T]),U]))};Array.prototype.selectFor=function(T,U,O,K){let X=this.find(T,K);if(X===void 0)throw Error(O??"Element not found");return U(X)};Array.prototype.sortBy=function(T,U=!0){return this.slice().sort((O,K)=>{let X=T(O),$=T(K);if(X<$)return U?-1:1;if(X>$)return U?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(T){let U=new Set;return this.filter((O)=>{let K=T(O);if(U.has(K))return!1;else return U.add(K),!0})};var
|
|
1
|
+
Array.prototype.findOrFail=function(T,U,O){let K=this.find(T,O);if(K===void 0)throw Error(U??"Element not found");return K};Array.flat=function(T){if(Array.isArray(T))return T.flat(2);else return[T]};Array.prototype.forEachAsync=async function(T){for(let U=0;U<this.length;U++)await T(this[U],U,this)};Array.prototype.groupBy=function(T){return this.reduce((U,O)=>{let K=T(O);if(!U[K])U[K]=[];return U[K].push(O),U},{})};Array.prototype.createInstances=function(T,...U){return this.map((O,K)=>new T(...U,O,K))};Array.prototype.mapAsync=async function(T){return Promise.all(this.map(T))};Array.prototype.nonNullMap=function(T){let U=[];for(let O=0;O<this.length;O++){let K=T(this[O],O,this);if(K!=null)U.push(K)}return U};Array.prototype.nonNullMapAsync=async function(T){let U=[];for(let O=0;O<this.length;O++){let K=await T(this[O],O,this);if(K!=null)U.push(K)}return U};Array.prototype.mergeAll=function(T){let U={};for(let O of this.slice().reverse())Object.merge(O,U,T);return U};Array.prototype.toObject=function(T,U){return Object.fromEntries(this.map((O)=>{let K=T(O),X=U?U(O):O;return[K,X]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((U)=>[String(U[T]),U]))};Array.prototype.selectFor=function(T,U,O,K){let X=this.find(T,K);if(X===void 0)throw Error(O??"Element not found");return U(X)};Array.prototype.sortBy=function(T,U=!0){return this.slice().sort((O,K)=>{let X=T(O),$=T(K);if(X<$)return U?-1:1;if(X>$)return U?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(T){let U=new Set;return this.filter((O)=>{let K=T(O);if(U.has(K))return!1;else return U.add(K),!0})};var P;((A)=>{A[A.Explore=0]="Explore";A[A.SkipSiblings=1]="SkipSiblings";A[A.NoExplore=2]="NoExplore";A[A.ReplaceParent=3]="ReplaceParent";A[A.DeleteParent=4]="DeleteParent";A[A.MergeParent=5]="MergeParent";A[A.ReplaceItem=6]="ReplaceItem";A[A.DeleteItem=7]="DeleteItem"})(P||={});class Y{action;by;skipSiblings;reexplore;constructor(T,U,O,K){this.action=T;this.by=U;this.skipSiblings=O;this.reexplore=K}static _explore=new Y(0);static _noExplore=new Y(2);static _skipSiblings=new Y(1);static _deleteParent=new Y(4);static ReplaceParent(T,U){return new Y(3,T,void 0,U)}static SkipSiblings(){return Y._skipSiblings}static Explore(){return Y._explore}static NoExplore(){return Y._noExplore}static DeleteParent(){return Y._deleteParent}static MergeParent(T){return new Y(5,T)}static ReplaceItem(T,U){return new Y(6,T,U)}static DeleteItem(T){return new Y(7,void 0,T)}}Object.navigate=async(T,U)=>{let O=new WeakSet,K=[],X=[],$=async(F,A,J)=>{let Q=F===null,_=Q?Y.Explore():await U({key:F,value:A,path:K,parent:J,parents:X});if(A&&typeof A==="object"&&_.action===0){if(O.has(A))return _;if(O.add(A),!Q)K.push(F),X.push(J);let G=A;while(await j(G,F,J))G=J[F];if(!Q)X.pop(),K.pop()}return _},j=async(F,A,J)=>{let Q=Object.keys(F),Z=Q.length;for(let _=0;_<Z;_++){let B=Q[_],b=F[B],G=await $(B,b,F),E=G.action;if(E===0||E===2)continue;if(E===6){if(F[B]=G.by,G.skipSiblings)return;continue}if(E===7){if(delete F[B],G.skipSiblings)return;continue}if(E===1)return;if(E===3){if(A===null)throw Error("Cannot replace root object");if(J[A]=G.by,G.reexplore)return!0;return}if(E===4){if(A===null)throw Error("Cannot delete root object");delete J[A];return}if(E===5)delete F[B],Object.assign(F,G.by)}};await $(null,T,null)};Object.find=async function(T,U){let O=[];return await Object.navigate(T,(K)=>{if(U([...K.path,K.key].join("."),K.value))O.push(K.value);return Y.Explore()}),O};Object.merge=(T,U,O)=>{for(let K of Object.keys(U)){if(T[K]===void 0)continue;let X=U[K],$=T[K];if(typeof $!==typeof X||Array.isArray($)!==Array.isArray(X)){let F=O?.mismatch?.(K,$,X,T,U);if(F!==void 0){U[K]=F;continue}throw Error(`Type mismatch: ${K}`)}let j=O?.mode?.(K,$,X,T,U)??U[".merge"]??"merge";switch(j){case"source":U[K]=$;continue;case"target":continue;case"skip":delete U[K],delete T[K];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${j}`)}if(typeof $==="object")if(Array.isArray($))X.push(...$);else{if(O?.navigate?.(K,$,X,T,U)===!1)continue;Object.merge($,X,O)}else{if($===X)continue;let F=O?.conflict?.(K,$,X,T,U);U[K]=F===void 0?X:F}}for(let K of Object.keys(T))if(U[K]===void 0)U[K]=T[K]};var x=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,R=/^([^[\]]*)\[([^\]]*)]$/,D=(T,U,O,K)=>{if(T.startsWith("{")&&T.endsWith("}")){let X=T.substring(1,T.length-1);return Object.select(U,X,O)?.toString()}return K?T:void 0},S=(T,U,O,K)=>{let X=D(U,O,K);if(X)return Object.select(T,X,K);let $=x.exec(U);if($){let[,F,A,J]=$,Q=D(F.trim(),O,K,!0),Z=D(J.trim(),O,K,!0);if(Array.isArray(T)&&(A==="="||A==="==")&&Q)return T.find((_)=>_?.[Q]==Z)}let j=R.exec(U);if(j){let[,F,A]=j;return T?.[F]?.[A]}return T?.[U]};Object.select=(T,U,O)=>{let K=void 0,X=void 0,$=U??"",j=(Z)=>{if(!Z)return[Z,!1];return Z.endsWith("?")?[Z.substring(0,Z.length-1),!0]:[Z,!1]},F=(Z,_)=>{let[B,b]=j(_.pop());if(!B){if(O?.set!==void 0&&X!==void 0&&K!==void 0)K[X]=O.set;return Z}let G=S(Z,B,T,O);if(G===void 0){if(b||O?.optional||O?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${B}" in "${$}"`)}return K=Z,X=B,F(G,_)},A=$.splitNested(O?.separator??".","{","}"),J=void 0;if(A.length>0&&A[A.length-1].startsWith("?="))J=A.pop()?.substring(2);A.reverse();let Q=F(T,A);if(Q===void 0)return J??O?.defaultValue;return Q};Object.deepClone=function(T){if(typeof structuredClone<"u")try{return structuredClone(T)}catch{}return JSON.parse(JSON.stringify(T))};Object.toList=function(T,U){return Object.entries(T).map(([O,K])=>({[U]:O,...K}))};Object.mapEntries=function(T,U){let K=Object.entries(T).map(([X,$])=>U(X,$));return Object.fromEntries(K)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(T,U="Value is undefined")=>{if(T===void 0||T===null)throw Error(U);return T};global.createAsyncFunction=(T,U,O)=>{let K=new AsyncFunction(...Object.keys(U??{}),T);return O?K.bind(O):K};global.runAsyncFunction=async(T)=>{let{body:U,args:O={},thisArg:K}=T,X=createAsyncFunction(U,O,K);try{return await X(...Object.values(O))}catch($){if(T.onError)return T.onError($);throw $}};String.prototype.tokenize=function(T,U=/\${([^}]+)}/g){return this.replace(U,(O,K)=>{let X=T[K];if(X===null||X===void 0)return"";if(typeof X==="string")return X;if(typeof X==="number"||typeof X==="boolean")return String(X);return String(X)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(T,U)=>U.toUpperCase()).replace(/[^a-zA-Z0-9 ]/g,"").replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(T,U)=>U.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(T,U)=>U.toLowerCase())};String.prototype.toSnake=function(){return this.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/\s+/g,"_")};String.prototype.toKebab=function(){return this.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/\s+/g,"-")};String.prototype.changeCase=function(T){switch(T){case"upper":return this.toUpperCase();case"lower":return this.toLowerCase();case"pascal":return this.toPascal();case"camel":return this.toCamel();case"snake":return this.toSnake();case"kebab":return this.toKebab();default:throw Error(`Unsupported case type: ${T}`)}};String.prototype.splitWithQuotes=function(T=","){let U=[],O=this.length,K=T.length,X=0,$=(j)=>{if(j+K>O)return!1;for(let F=0;F<K;F++)if(this[j+F]!==T[F])return!1;return!0};while(X<O){while(X<O&&this[X]===" ")X++;if(X>=O)break;let j="",F=this[X]==='"'||this[X]==="'";if(F){let A=this[X++];while(X<O&&this[X]!==A)j+=this[X++];if(X<O)X++}else{while(X<O&&!$(X)){let A=this[X];if(A==='"'||A==="'"){j+=A,X++;while(X<O&&this[X]!==A)j+=this[X++];if(X<O)j+=this[X++]}else j+=this[X++]}j=j.trim()}if(j)U.push({value:j,quoted:F});if($(X))X+=K}return U};String.prototype.splitNested=function(T,U,O){let K=0,X="",$=[];for(let j of this){if(X+=j,j===U)K++;if(j===O)K--;if(K===0&&j===T)$.push(X.slice(0,-1)),X=""}if(X)$.push(X);return $};String.prototype.toStringBuilder=function(){return new H(this.split(`
|
|
2
2
|
`))};String.prototype.padBlock=function(T,U=`
|
|
3
3
|
`,O=" "){let K=O.repeat(T);return this.split(U).map((X)=>K+X).join(U)};String.prototype.stripIndent=function(){let T=this.split(/\r?\n/),U=T.filter((K)=>K.trim().length>0).map((K)=>/^[ \t]*/.exec(K)?.[0].length??0),O=U.length>0?Math.min(...U):0;if(O===0)return this;return T.map((K)=>K.slice(O)).join(`
|
|
4
|
-
`)};String.prototype.toHtmlLink=function(T){return`<a href="${T??this.toString()}">${this.toString()}</a>`};String.prototype.toHtml=function(){return this.toString().trim().replace(/[<>&"_]/g,(T)=>`&#${T.charCodeAt(0).toString()};`).replace(/\n/g,"<br/>")};String.prototype.toRgb=function(){let T=this.toString().replace("#","");if(T.length!==6)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16);return`rgb(${U.toString()}, ${O.toString()}, ${K.toString()})`};String.prototype.toArgb=function(){let T=this.toString().replace("#","");if(T.length!==8)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16),X=parseInt(T.substring(6,8),16);return`argb(${U.toString()}, ${O.toString()}, ${K.toString()}, ${X.toString()})`};var
|
|
4
|
+
`)};String.prototype.toHtmlLink=function(T){return`<a href="${T??this.toString()}">${this.toString()}</a>`};String.prototype.toHtml=function(){return this.toString().trim().replace(/[<>&"_]/g,(T)=>`&#${T.charCodeAt(0).toString()};`).replace(/\n/g,"<br/>")};String.prototype.toRgb=function(){let T=this.toString().replace("#","");if(T.length!==6)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16);return`rgb(${U.toString()}, ${O.toString()}, ${K.toString()})`};String.prototype.toArgb=function(){let T=this.toString().replace("#","");if(T.length!==8)throw Error("Invalid hex color");let U=parseInt(T.substring(0,2),16),O=parseInt(T.substring(2,4),16),K=parseInt(T.substring(4,6),16),X=parseInt(T.substring(6,8),16);return`argb(${U.toString()}, ${O.toString()}, ${K.toString()}, ${X.toString()})`};var y={red:"#FF0000",green:"#00FF00",blue:"#0000FF",yellow:"#FFFF00",cyan:"#00FFFF",magenta:"#FF00FF",white:"#FFFFFF",black:"#000000",orange:"#FFA500",purple:"#800080",pink:"#FFC0CB",gray:"#808080",grey:"#808080"};String.prototype.toColor=function(T){let U=this.toString().trim(),O,K,X;if(y[U])U=y[U];if(U.startsWith("#")){let $=U.slice(1);if($.length===3)O=parseInt($[0]+$[0],16),K=parseInt($[1]+$[1],16),X=parseInt($[2]+$[2],16);else if($.length===6)O=parseInt($.slice(0,2),16),K=parseInt($.slice(2,4),16),X=parseInt($.slice(4,6),16);else{if(T)return T;throw Error(`Invalid hex color: ${U}`)}return{r:O,g:K,b:X}}if(U.includes(";")){let $=U.split(";").map(Number);if($.length!==3||$.some(isNaN)){if(T)return T;throw Error(`Invalid RGB color string: ${U}`)}return{r:$[0],g:$[1],b:$[2]}}if(T)return T;throw Error(`Unsupported color string format: ${U}`)};String.prototype.colorize=function(T){let U=typeof T==="string"?T.toColor({r:255,g:255,b:255}):T;return`\x1B[38;2;${U.r.toString()};${U.g.toString()};${U.b.toString()}m${this.toString()}\x1B[0m`};String.prototype.single=function(T){return this.replaceAll(new RegExp(`(${T})+`,"g"),"$1")};String.prototype.remove=function(T){return this.replaceAll(new RegExp(T,"g"),"")};String.prototype.toAlphanum=function(T=""){return this.replace(/[^a-z0-9]/gi,T)};String.prototype.toAlpha=function(T=""){return this.replace(/[^a-z]/gi,T)};class m{options;#T=/(["'])(?:(?=(\\?))\2.)*?\1/g;#U=/<color=([^>]+)>(.*?)<\/color>/g;#O=/\b\d+(?:\.\d+)?\b/g;constructor(T){this.options={level:"INFO",showClass:!1,levels:["DEBUG","VERBOSE","INFO","WARN","ERROR"],timeStamp:!1,timeOptions:{second:"2-digit",minute:"2-digit",hour:"2-digit",day:"2-digit",month:"2-digit",year:"2-digit"},colors:{},...T}}write(T,...U){if(this.options.level){let X=this.options.levels.indexOf(this.options.level),$=this.options.levels.indexOf(T);if(X===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if($===-1)throw Error(`Unknown log level: ${T}`);if($<X)return}let O=[],K=[];if(this.options.timeStamp)K.push(this.onTime(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions),T));if(this.options.showClass)K.push(this.onClass(T));if(K.length>0)O.push(`[${K.join(" ")}]`);O.push(...U.map((X)=>this.onElement(X,T))),this.onLog(T,...O)}onTime(T,U){if(this.options.colors?.time)T=T.colorize(this.options.colors.time);return T}onClass(T){if(this.options.colors?.levels?.[T])T=T.colorize(this.options.colors.levels[T]);return T}onElement(T,U){if(typeof T==="number")return this.#K(T.toString(),this.options.colors?.number);if(typeof T==="string")return this.#A(T,this.options.colors?.default);return T}#K(T,U){if(!U)return T;return T.colorize(U)}#A(T,U){let O=[],K=0;while(K<T.length){let X=this.#$(T,K,this.#T,"quoted"),$=this.#$(T,K,this.#U,"color"),j=this.#$(T,K,this.#O,"number"),F=this.#X(X,$,j);if(!F){O.push(this.#K(T.slice(K),U));break}if(F.index>K)O.push(this.#K(T.slice(K,F.index),U));if(F.kind==="quoted")O.push(this.#K(F.match[0],this.options.colors?.quoted));else if(F.kind==="number")O.push(this.#K(F.match[0],this.options.colors?.number));else{let A=F.match[2]??"";O.push(this.#A(A,F.match[1]))}K=F.index+F.match[0].length}return O.join("")}#$(T,U,O,K){let X=new RegExp(O.source,O.flags);X.lastIndex=U;let $=X.exec(T);if(!$)return null;return{index:$.index,match:$,kind:K}}#X(T,U,O){let K=[T,U,O].filter((X)=>X!==null);if(K.length===0)return null;return K.reduce((X,$)=>$.index<X.index?$:X)}onLog(T,...U){switch(T){case"ERROR":console.error(...U);break;case"WARN":console.warn(...U);break;case"DEBUG":console.debug(...U);break;case"VERBOSE":console.log(...U);break;default:console.log(...U)}}info(...T){this.write("INFO",...T)}error(...T){this.write("ERROR",...T)}warn(...T){this.write("WARN",...T)}debug(...T){this.write("DEBUG",...T)}verbose(...T){this.write("VERBOSE",...T)}}class H{#T=[];#U=0;options;constructor(T,U){if(T instanceof H)this.options={...T.options,...U},this.#T.push(...T.#T);else if(this.options=U??{},T)if(Array.isArray(T))this.#T.push(...T);else this.#T.push(T)}setOptions(T){return this.options=T,this}clear(){return this.#T.length=0,this}isEmpty(){return this.#T.length===0}toString(){return this.#T.join("")}indent(){return this.#U+=1,this}dedent(){if(this.#U>0)this.#U-=1;return this}getCurrentIndent(){return this.#U}getLines(){return this.toString().split(`
|
|
5
5
|
`)}formatLine(T){T??=`
|
|
6
6
|
`;let U=(this.options.indentChar??" ").repeat(this.#U*(this.options.indentSize??2));if(this.options.trim)T=T.trim();return U+(this.options.linePrefix??"")+T+(this.options.lineSuffix??"")+(this.options.lineSeparator??`
|
|
7
|
-
`)}write(...T){return this.#T.push(...T.flatMap((U)=>{if(U!==void 0){if(typeof U==="string")return U;if(Array.isArray(U))return U.flat();if(U instanceof
|
|
8
|
-
`)}writeMap(T,U){return T.forEach((O,K)=>U(O,K,this)),this}}class
|
|
9
|
-
`).forEach((O)=>this.writeLine("> "+O)),this}bold(T){return this.write(`**${T}**`)}italic(T){return this.write(`*${T}*`)}item(T){return this.writeLine(`- ${T}`)}items(T){if(Array.isArray(T))T.forEach((U)=>this.item(U));else Object.entries(T).forEach(([U,O])=>O!==void 0&&this.item(`${U}: ${O!==void 0?String(O):""}`));return this}orderedList(T,U=1){return T.forEach((O,K)=>this.writeLine(`${(K+U).toString()}. ${O}`)),this}code(T){return this.write(`\`${T}\``)}horizontalRule(){return this.writeLine("---")}image(T,U){return this.writeLine(``)}strikethrough(T){return this.write(`~~${T}~~`)}highlight(T){return this.write(`==${T}==`)}subscript(T){return this.write(`~${T}~`)}superscript(T){return this.write(`^${T}^`)}taskList(T){return T.forEach((U)=>this.writeLine(`- [${U.checked?"x":" "}] ${U.text}`)),this}section(T,U){if(U!==void 0)this.#T=this.#O(U);else this.#T=Math.min(6,this.#T+1);return this.header(T,this.#T)}endSection(){if(this.#T>0)this.#T--;return this}setSectionLevel(T){return this.#T=Math.min(6,Math.max(0,Math.floor(T))),this}}class
|
|
10
|
-
`);U.push("","Options:");for(let O of this.#U){let K=`--${O.name}`,X=O.alias?`-${O.alias}`:void 0,$=O.valueName??"value",
|
|
11
|
-
`)}#
|
|
7
|
+
`)}write(...T){return this.#T.push(...T.flatMap((U)=>{if(U!==void 0){if(typeof U==="string")return U;if(Array.isArray(U))return U.flat();if(U instanceof H)return U.toString();if(typeof U==="function")return U(this);return String(U)}}).filter((U)=>U!==void 0)),this}writeLine(...T){return this.write(T.length>0?T.map((U)=>this.formatLine(U)):`
|
|
8
|
+
`)}writeMap(T,U){return T.forEach((O,K)=>U(O,K,this)),this}}class k extends H{#T=0;#U="```";#O(T){return Math.min(6,Math.max(1,Math.floor(T)))}#K(T){if(T===void 0)return"```";let U=0;for(let O of T.matchAll(/`+/g))U=Math.max(U,O[0].length);return"`".repeat(Math.max(3,U+1))}header(T,U=1){let O=this.#O(U);return this.writeLine(`${"#".repeat(O)} ${T}`,"")}codeBlock(T,U){let O=this.#K(T);if(this.#U=O,U??="",this.writeLine(O+U),T!==void 0)this.writeLine(T).endCodeBlock();return this}endCodeBlock(){let T=this.#U;return this.#U="```",this.writeLine(T)}link(T,U,O){if(O)return this.write(`[${T}](${U} "${O}")`);return this.write(`[${T}](${U})`)}table(T,U){if(T.length===0)throw Error("Table requires at least one header");let O=T.map(($,j)=>{let F=$.length;return U.forEach((A)=>{if(A[j])F=Math.max(F,A[j].length)}),F}),K=T.map(($,j)=>$.padEnd(O[j]));this.writeLine("| "+K.join(" | ")+" |");let X=O.map(($)=>"-".repeat($));return this.writeLine("| "+X.join(" | ")+" |"),U.forEach(($)=>{let j=T.map((F,A)=>($[A]??"").padEnd(O[A]));this.writeLine("| "+j.join(" | ")+" |")}),this}blockquote(T){return T.split(`
|
|
9
|
+
`).forEach((O)=>this.writeLine("> "+O)),this}bold(T){return this.write(`**${T}**`)}italic(T){return this.write(`*${T}*`)}item(T){return this.writeLine(`- ${T}`)}items(T){if(Array.isArray(T))T.forEach((U)=>this.item(U));else Object.entries(T).forEach(([U,O])=>O!==void 0&&this.item(`${U}: ${O!==void 0?String(O):""}`));return this}orderedList(T,U=1){return T.forEach((O,K)=>this.writeLine(`${(K+U).toString()}. ${O}`)),this}code(T){return this.write(`\`${T}\``)}horizontalRule(){return this.writeLine("---")}image(T,U){return this.writeLine(``)}strikethrough(T){return this.write(`~~${T}~~`)}highlight(T){return this.write(`==${T}==`)}subscript(T){return this.write(`~${T}~`)}superscript(T){return this.write(`^${T}^`)}taskList(T){return T.forEach((U)=>this.writeLine(`- [${U.checked?"x":" "}] ${U.text}`)),this}section(T,U){if(U!==void 0)this.#T=this.#O(U);else this.#T=Math.min(6,this.#T+1);return this.header(T,this.#T)}endSection(){if(this.#T>0)this.#T--;return this}setSectionLevel(T){return this.#T=Math.min(6,Math.max(0,Math.floor(T))),this}}class N{#T;#U;#O=new Map;#K=[];constructor(T,U=[]){this.#T=[...T],this.#U=[...U],this.#A()}get args(){return[...this.#T]}get positionals(){return[...this.#K]}has(T){return this.#O.has(this.#X(T))}getArgs(T){return[...this.#O.get(this.#X(T))?.values??[]]}get(T){let U=this.#O.get(this.#X(T))?.values;if(!U)return;if(U.length===0)return!0;return U[0]}toObject(){let T={};for(let[U,O]of this.#O.entries())T[U]=O.values.length>0?[...O.values]:!0;return T}usage(T="command"){let U=[`Usage: ${T} [options]`];if(this.#K.length>0)U[0]+=" [values]";if(this.#U.length===0)return U.join(`
|
|
10
|
+
`);U.push("","Options:");for(let O of this.#U){let K=`--${O.name}`,X=O.alias?`-${O.alias}`:void 0,$=O.valueName??"value",j=O.takesValue?O.multiple?` <${$}...>`:` <${$}>`:"",F=X?`${X}, ${K}`:K,A=O.description?` ${O.description}`:"";U.push(` ${F}${j}${A}`)}return U.join(`
|
|
11
|
+
`)}#A(){for(let T=0;T<this.#T.length;T++){let U=this.#T[T];if(!U.startsWith("-")||U==="-"){this.#K.push(U);continue}if(U.startsWith("--")&&U.includes("=")){let X=U.indexOf("="),$=this.#X(U.slice(0,X)),j=U.slice(X+1);this.#$($,j.length>0?[j]:[""],!0);continue}let O=this.#X(U),K=[];while(T+1<this.#T.length){let X=this.#T[T+1];if(X.startsWith("-")&&X!=="-")break;K.push(X),T++}this.#$(O,K,!1)}}#$(T,U,O){let K=this.#O.get(T);if(!K){this.#O.set(T,{values:[...U],sawEqualsStyle:O});return}K.values.push(...U),K.sawEqualsStyle=K.sawEqualsStyle||O}#X(T){return T.replace(/^-+/,"").trim()}}import z from"fs/promises";var C=async(T)=>{try{return await z.access(T,z.constants.R_OK),!0}catch{return!1}};import q from"path";var L=async(T,U)=>{let O=!q.isAbsolute(T)&&U?["",...U]:[""];for(let K of O){let X=q.join(K,T);if(await C(X))return q.resolve(X)}throw Error(`File not found: "${T}"`)};import d from"fs/promises";import h from"path";var v=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,cT=async(T,U)=>{let O=await L(T,U?.dirs),K=await d.readFile(O,"utf-8"),X=h.dirname(O),$={text:{fn:(A)=>A,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...U?.parsers},j=U?.format?$[U.format]:Object.values($).find((A)=>v(T,A.matching));if(!j)throw Error(`Unsupported format for file "${T}" and no matching parser found`);return{content:await j.fn(K),fullPath:O,folderPath:X}};import p from"fs/promises";var g=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,V=async(T,U,O)=>{let K={text:{fn:($)=>$,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...O?.encoders},X=O?.format?K[O.format]:Object.values(K).find(($)=>g(T,$.matching));if(!X)throw Error(`Unsupported format for file "${T}" and no matching encoder found`);await p.writeFile(T,await X.fn(U))};import u from"fs/promises";var lT=async(T,U)=>{if(typeof T==="string"&&!T.includes("*"))return await U.map(T,0,[]);let O=await Array.fromAsync(u.glob(T,{cwd:U.cwd})),K=U.filter?O.filter(U.filter):O;return await Promise.all(K.map(U.map))};import w from"fs/promises";import M from"path";var TU=async(T,U)=>{if(U?.targetDirectory&&U?.removeFirst)try{await w.rm(U?.targetDirectory,{recursive:!0,force:!0})}catch(O){throw Error(`Failed to clean the output directory: ${O.message}`,{cause:O})}for(let O of T)await c(O,U)},c=async(T,U)=>{let O=M.join(U?.targetDirectory??".",T.name),K=M.dirname(O);if(U?.classes){if(T.class!==void 0&&!U.classes.includes(T.class))return;if(U.classRequired&&T.class===void 0)throw Error(`Output "${T.name}" is missing class field`)}if(U?.writing?.(T)===!1)return;try{await w.mkdir(K,{recursive:!0})}catch(X){throw Error(`Failed to create target directory "${K}" for output "${O}": ${X.message}`,{cause:X})}try{await V(O,T.value,{format:T.type??"text"})}catch(X){throw Error(`Failed to write output "${O}": ${X.message}`,{cause:X})}};import r from"fs/promises";import W from"path";import f from"path";var I=(T)=>T?f.isAbsolute(T)?T:f.join(process.cwd(),T):process.cwd();var n=async(T,U)=>{let O=[];for(let K of T)try{let X=!W.isAbsolute(K)?W.join(I(U?.cwd),K):K;if(U?.filter?.(X)===!1)continue;let $=await import(X);if(U?.resolveDefault==="only"&&!$.default)throw Error(`Module ${K} does not have a default export`);let j=U?.resolveDefault?$.default??$:$,F=U?.map?await U.map(j,K):j;if(F!==void 0)O.push(F)}catch(X){if(U?.fail?.(K,X)===!1)continue;throw Error(`Failed to import module ${K}: ${X.message??X}`,{cause:X})}return O},FU=async(T,U)=>{let O=[],K=I(U?.cwd);for(let X of T){let $=(await Array.fromAsync(r.glob(X,{cwd:K}))).map((j)=>W.join(K,j));O.push(...await n($,U))}return O};class o{#T={};#U(T,U,O){return{handler:T,calls:0,cleared:!1,mode:U,errorMode:"throw",...O}}#O(T){return this.#T[T]??=[]}on(T,U,O){return this.#O(T).push(this.#U(U,"on",O)),this}once(T,U,O){return this.#O(T).push(this.#U(U,"once",O)),this}clear(T){return this.#T[T]=[],this}getListeners(T){return this.#O(T)}async emit(T,U){let O=this.#O(T);if(!O)return!0;let K=null,X=null,$=!0;for(let j of O){let F;try{F=await j.handler(U,j)}catch(A){K=A,X=j}if(j.calls++,j.mode==="once")j.cleared=!0;if(typeof F==="boolean"){$=F;break}if(K&&j.errorMode!=="continue")break}if(this.#T[T]=O.filter((j)=>!j.cleared),K&&X?.errorMode==="throw")throw K;return $}}export{TU as writeOutputs,c as writeOutput,V as writeFormat,L as locate,cT as loadFormat,n as importList,FU as importGlob,lT as globMap,I as getCwd,C as exists,H as StringBuilder,Y as NavigateResult,P as NavigateAction,k as Markdown,m as Logger,N as CommandLineArgs,o as AsyncEmitter};
|