@homedev/framework 1.0.13 → 1.0.15
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 -0
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -743,6 +743,7 @@ declare global {
|
|
|
743
743
|
navigate(o: any, cb: NavigateCallback): Promise<void>;
|
|
744
744
|
find(from: any, cb: (path: string, value: any) => boolean): Promise<any[]>;
|
|
745
745
|
select(from: any, path: string, options?: SelectOptions): any;
|
|
746
|
+
wrap<T extends Record<string, U>, U = T[keyof T]>(data: U, key: keyof T): T;
|
|
746
747
|
}
|
|
747
748
|
}
|
|
748
749
|
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
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),A=U?U(O):O;return[K,A]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((U)=>[String(U[T]),U]))};Array.prototype.selectFor=function(T,U,O,K){let A=this.find(T,K);if(A===void 0)throw Error(O??"Element not found");return U(A)};Array.prototype.sortBy=function(T,U=!0){return this.slice().sort((O,K)=>{let A=T(O),X=T(K);if(A<X)return U?-1:1;if(A>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})};Array.prototype.last=function(){if(this.length===0)return;return this[this.length-1]};Array.prototype.allButLast=function(){if(this.length===0)return[];return this.slice(0,this.length-1)};Array.prototype.pushValue=function(...T){for(let U of T)if(U!==null&&U!==void 0)this.push(U);return this};Array.prototype.pushIf=function(T,...U){if(T)this.push(...U);return this};var h;((F)=>{F[F.Explore=0]="Explore";F[F.SkipSiblings=1]="SkipSiblings";F[F.NoExplore=2]="NoExplore";F[F.ReplaceParent=3]="ReplaceParent";F[F.DeleteParent=4]="DeleteParent";F[F.MergeParent=5]="MergeParent";F[F.ReplaceItem=6]="ReplaceItem";F[F.DeleteItem=7]="DeleteItem"})(h||={});class H{action;by;skipSiblings;reexplore;constructor(T,U,O,K){this.action=T;this.by=U;this.skipSiblings=O;this.reexplore=K}static _explore=new H(0);static _noExplore=new H(2);static _skipSiblings=new H(1);static _deleteParent=new H(4);static ReplaceParent(T,U){return new H(3,T,void 0,U)}static SkipSiblings(){return H._skipSiblings}static Explore(){return H._explore}static NoExplore(){return H._noExplore}static DeleteParent(){return H._deleteParent}static MergeParent(T){return new H(5,T)}static ReplaceItem(T,U){return new H(6,T,U)}static DeleteItem(T){return new H(7,void 0,T)}}Object.navigate=async(T,U)=>{let O=new WeakSet,K=[],A=[],X=async($,F,Q)=>{let D=$===null,
|
|
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),A=U?U(O):O;return[K,A]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((U)=>[String(U[T]),U]))};Array.prototype.selectFor=function(T,U,O,K){let A=this.find(T,K);if(A===void 0)throw Error(O??"Element not found");return U(A)};Array.prototype.sortBy=function(T,U=!0){return this.slice().sort((O,K)=>{let A=T(O),X=T(K);if(A<X)return U?-1:1;if(A>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})};Array.prototype.last=function(){if(this.length===0)return;return this[this.length-1]};Array.prototype.allButLast=function(){if(this.length===0)return[];return this.slice(0,this.length-1)};Array.prototype.pushValue=function(...T){for(let U of T)if(U!==null&&U!==void 0)this.push(U);return this};Array.prototype.pushIf=function(T,...U){if(T)this.push(...U);return this};var h;((F)=>{F[F.Explore=0]="Explore";F[F.SkipSiblings=1]="SkipSiblings";F[F.NoExplore=2]="NoExplore";F[F.ReplaceParent=3]="ReplaceParent";F[F.DeleteParent=4]="DeleteParent";F[F.MergeParent=5]="MergeParent";F[F.ReplaceItem=6]="ReplaceItem";F[F.DeleteItem=7]="DeleteItem"})(h||={});class H{action;by;skipSiblings;reexplore;constructor(T,U,O,K){this.action=T;this.by=U;this.skipSiblings=O;this.reexplore=K}static _explore=new H(0);static _noExplore=new H(2);static _skipSiblings=new H(1);static _deleteParent=new H(4);static ReplaceParent(T,U){return new H(3,T,void 0,U)}static SkipSiblings(){return H._skipSiblings}static Explore(){return H._explore}static NoExplore(){return H._noExplore}static DeleteParent(){return H._deleteParent}static MergeParent(T){return new H(5,T)}static ReplaceItem(T,U){return new H(6,T,U)}static DeleteItem(T){return new H(7,void 0,T)}}Object.navigate=async(T,U)=>{let O=new WeakSet,K=[],A=[],X=async($,F,Q)=>{let D=$===null,y=D?H.Explore():await U({key:$,value:F,path:K,parent:Q,parents:A});if(F&&typeof F==="object"&&y.action===0){if(O.has(F))return y;if(O.add(F),!D)K.push($),A.push(Q);let Y=F;while(await j(Y,$,Q))Y=Q[$];if(!D)A.pop(),K.pop()}return y},j=async($,F,Q)=>{let D=Object.keys($),_=D.length;for(let y=0;y<_;y++){let J=D[y],G=$[J],Y=await X(J,G,$),Z=Y.action;if(Z===0||Z===2)continue;if(Z===6){if($[J]=Y.by,Y.skipSiblings)return;continue}if(Z===7){if(delete $[J],Y.skipSiblings)return;continue}if(Z===1)return;if(Z===3){if(F===null)throw Error("Cannot replace root object");if(Q[F]=Y.by,Y.reexplore)return!0;return}if(Z===4){if(F===null)throw Error("Cannot delete root object");delete Q[F];return}if(Z===5)delete $[J],Object.assign($,Y.by)}};await X(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 H.Explore()}),O};Object.merge=(T,U,O)=>{for(let K of Object.keys(U)){if(T[K]===void 0)continue;let A=U[K],X=T[K];if(typeof X!==typeof A||Array.isArray(X)!==Array.isArray(A)){let $=O?.mismatch?.(K,X,A,T,U);if($!==void 0){U[K]=$;continue}throw Error(`Type mismatch: ${K}`)}let j=O?.mode?.(K,X,A,T,U)??U[".merge"]??"merge";switch(j){case"source":U[K]=X;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 X==="object")if(Array.isArray(X))A.push(...X);else{if(O?.navigate?.(K,X,A,T,U)===!1)continue;Object.merge(X,A,O)}else{if(X===A)continue;let $=O?.conflict?.(K,X,A,T,U);U[K]=$===void 0?A:$}}for(let K of Object.keys(T))if(U[K]===void 0)U[K]=T[K]};Object.wrap=function(T,U){return{[U]:T}};var u=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,v=/^([^[\]]*)\[([^\]]*)]$/,E=(T,U,O,K)=>{if(T.startsWith("{")&&T.endsWith("}")){let A=T.substring(1,T.length-1);return Object.select(U,A,O)?.toString()}return K?T:void 0},p=(T,U,O,K)=>{let A=E(U,O,K);if(A)return Object.select(T,A,K);let X=u.exec(U);if(X){let[,$,F,Q]=X,D=E($.trim(),O,K,!0),_=E(Q.trim(),O,K,!0);if(Array.isArray(T)&&(F==="="||F==="==")&&D)return T.find((y)=>y?.[D]==_)}let j=v.exec(U);if(j){let[,$,F]=j;return T?.[$]?.[F]}return T?.[U]};Object.select=(T,U,O)=>{let K=void 0,A=void 0,X=U??"",j=(_)=>{if(!_)return[_,!1];return _.endsWith("?")?[_.substring(0,_.length-1),!0]:[_,!1]},$=(_,y)=>{let[J,G]=j(y.pop());if(!J){if(O?.set!==void 0&&A!==void 0&&K!==void 0)K[A]=O.set;return _}let Y=p(_,J,T,O);if(Y===void 0){if(G||O?.optional||O?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${J}" in "${X}"`)}return K=_,A=J,$(Y,y)},F=X.splitNested(O?.separator??".","{","}"),Q=void 0;if(F.length>0&&F[F.length-1].startsWith("?="))Q=F.pop()?.substring(2);F.reverse();let D=$(T,F);if(D===void 0)return Q??O?.defaultValue;return D};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(([A,X])=>U(A,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,A=createAsyncFunction(U,O,K);try{return await A(...Object.values(O))}catch(X){if(T.onError)return T.onError(X);throw X}};String.prototype.tokenize=function(T,U=/\${([^}]+)}/g){return this.replace(U,(O,K)=>{let A=T[K];if(A===null||A===void 0)return"";if(typeof A==="string")return A;if(typeof A==="number"||typeof A==="boolean")return String(A);return String(A)})};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,A=0,X=(j)=>{if(j+K>O)return!1;for(let $=0;$<K;$++)if(this[j+$]!==T[$])return!1;return!0};while(A<O){while(A<O&&this[A]===" ")A++;if(A>=O)break;let j="",$=this[A]==='"'||this[A]==="'";if($){let F=this[A++];while(A<O&&this[A]!==F)j+=this[A++];if(A<O)A++}else{while(A<O&&!X(A)){let F=this[A];if(F==='"'||F==="'"){j+=F,A++;while(A<O&&this[A]!==F)j+=this[A++];if(A<O)j+=this[A++]}else j+=this[A++]}j=j.trim()}if(j)U.push({value:j,quoted:$});if(X(A))A+=K}return U};String.prototype.splitNested=function(T,U,O){let K=0,A="",X=[];for(let j of this){if(A+=j,j===U)K++;if(j===O)K--;if(K===0&&j===T)X.push(A.slice(0,-1)),A=""}if(A)X.push(A);return X};String.prototype.toStringBuilder=function(){return new q(this.split(`
|
|
2
2
|
`))};String.prototype.findBlocks=function(T){let U=[],O=this.length,K=T?.open??"",A=T?.close??"",X=K.length,j=A.length,$=T?.rangeStart??0,F=T?.rangeEnd??O;if(X===0||j===0||$>=F)return U;let Q=(G)=>{let Y=this.lastIndexOf(`
|
|
3
3
|
`,G-1);return Y===-1?0:Y+1},D=(G,Y)=>{let Z=this.indexOf(`
|
|
4
4
|
`,G);return Z===-1||Z>Y?Y-G:Z-G},_=(G,Y)=>{if(Y<=G)return 0;let Z=this.lastIndexOf(`
|
|
5
|
-
`,Y-1);return Z<G?Y-G:Y-(Z+1)},
|
|
6
|
-
`);if(f!==-1)Z=Z.substring(f+1)}Z=
|
|
5
|
+
`,Y-1);return Z<G?Y-G:Y-(Z+1)},y=(G)=>{let Y=G.length-1;while(Y>=0&&(G.charCodeAt(Y)===32||G.charCodeAt(Y)===9))Y--;if(Y>=0&&G.charCodeAt(Y)===10)return G.substring(0,Y);return G},J=this.indexOf(K,$);while(J!==-1&&J<F){let G=J+X,Y=this.indexOf(A,G);if(Y===-1||Y>=F)break;let Z=this.substring(G,Y),M=J-Q(J),w=D(G,Y),N=_(J,Y),b=Y+j,k=b<O?1:0;if(w===0){let f=Z.indexOf(`
|
|
6
|
+
`);if(f!==-1)Z=Z.substring(f+1)}Z=y(Z);let B=Math.max(Z.getIndentation()-M,0);if(T?.reindent&&B>0)Z=Z.reindent(B);if(T?.trim)Z=Z.trim();U.push({content:Z,indentation:B,start:J,end:b,openTagIndentation:M,openTagPostIndentation:w,endTagIndentation:N,endTagPostIndentation:k}),J=this.indexOf(K,b)}return U};String.prototype.toWords=function(T){let O=new Map((T??[]).map(($)=>[$.open,$.close])),K=[],A=[],X="",j=()=>{if(X.length>0)K.push(X),X=""};for(let $ of this){let F=A[A.length-1];if(A.length===0&&/\s/.test($)){j();continue}if(X+=$,F&&$===F){A.pop();continue}let Q=O.get($);if(Q)A.push(Q)}return j(),K};String.prototype.padBlock=function(T,U=`
|
|
7
7
|
`,O=" "){let K=O.repeat(T);return this.split(U).map((A)=>K+A).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(`
|
|
8
8
|
`)};String.prototype.getIndentation=function(){let U=this.split(/\r?\n/).filter((O)=>O.trim().length>0).map((O)=>/^[ \t]*/.exec(O)?.[0].length??0);return U.length>0?Math.min(...U):0};String.prototype.reindent=function(T,U=`
|
|
9
9
|
`,O=" "){return this.stripIndent().padBlock(T,U,O)};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),A=parseInt(T.substring(6,8),16);return`argb(${U.toString()}, ${O.toString()}, ${K.toString()}, ${A.toString()})`};var C={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,A;if(C[U])U=C[U];if(U.startsWith("#")){let X=U.slice(1);if(X.length===3)O=parseInt(X[0]+X[0],16),K=parseInt(X[1]+X[1],16),A=parseInt(X[2]+X[2],16);else if(X.length===6)O=parseInt(X.slice(0,2),16),K=parseInt(X.slice(2,4),16),A=parseInt(X.slice(4,6),16);else{if(T)return T;throw Error(`Invalid hex color: ${U}`)}return{r:O,g:K,b:A}}if(U.includes(";")){let X=U.split(";").map(Number);if(X.length!==3||X.some(isNaN)){if(T)return T;throw Error(`Invalid RGB color string: ${U}`)}return{r:X[0],g:X[1],b:X[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)};String.prototype.mapLinesAsync=async function(T,U=`
|
|
10
10
|
`){return(await Promise.all(this.split(U).map(T))).filter((O)=>O!==null&&O!==void 0).join(U)};String.prototype.mapLines=function(T,U=`
|
|
11
|
-
`){return this.split(U).map(T).filter((O)=>O!==null&&O!==void 0).join(U)};class g{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 A=this.options.levels.indexOf(this.options.level),X=this.options.levels.indexOf(T);if(A===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(X===-1)throw Error(`Unknown log level: ${T}`);if(X<A)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((A)=>this.onElement(A,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.#$(T,this.options.colors?.default);return T}#K(T,U){if(!U)return T;return T.colorize(U)}#$(T,U){let O=[],K=0;while(K<T.length){let A=this.#X(T,K,this.#T,"quoted"),X=this.#X(T,K,this.#U,"color"),j=this.#X(T,K,this.#O,"number"),$=this.#A(A,X,j);if(!$){O.push(this.#K(T.slice(K),U));break}if($.index>K)O.push(this.#K(T.slice(K,$.index),U));if($.kind==="quoted")O.push(this.#K($.match[0],this.options.colors?.quoted));else if($.kind==="number")O.push(this.#K($.match[0],this.options.colors?.number));else{let F=$.match[2]??"";O.push(this.#$(F,$.match[1]))}K=$.index+$.match[0].length}return O.join("")}#X(T,U,O,K){let A=new RegExp(O.source,O.flags);A.lastIndex=U;let X=A.exec(T);if(!X)return null;return{index:X.index,match:X,kind:K}}#A(T,U,O){let K=[T,U,O].filter((A)=>A!==null);if(K.length===0)return null;return K.reduce((A,X)=>X.index<A.index?X:A)}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
|
|
11
|
+
`){return this.split(U).map(T).filter((O)=>O!==null&&O!==void 0).join(U)};class g{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 A=this.options.levels.indexOf(this.options.level),X=this.options.levels.indexOf(T);if(A===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(X===-1)throw Error(`Unknown log level: ${T}`);if(X<A)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((A)=>this.onElement(A,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.#$(T,this.options.colors?.default);return T}#K(T,U){if(!U)return T;return T.colorize(U)}#$(T,U){let O=[],K=0;while(K<T.length){let A=this.#X(T,K,this.#T,"quoted"),X=this.#X(T,K,this.#U,"color"),j=this.#X(T,K,this.#O,"number"),$=this.#A(A,X,j);if(!$){O.push(this.#K(T.slice(K),U));break}if($.index>K)O.push(this.#K(T.slice(K,$.index),U));if($.kind==="quoted")O.push(this.#K($.match[0],this.options.colors?.quoted));else if($.kind==="number")O.push(this.#K($.match[0],this.options.colors?.number));else{let F=$.match[2]??"";O.push(this.#$(F,$.match[1]))}K=$.index+$.match[0].length}return O.join("")}#X(T,U,O,K){let A=new RegExp(O.source,O.flags);A.lastIndex=U;let X=A.exec(T);if(!X)return null;return{index:X.index,match:X,kind:K}}#A(T,U,O){let K=[T,U,O].filter((A)=>A!==null);if(K.length===0)return null;return K.reduce((A,X)=>X.index<A.index?X:A)}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 q{#T=[];#U=0;options;constructor(T,U){if(T instanceof q)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(`
|
|
12
12
|
`)}formatLine(T){T??=`
|
|
13
13
|
`;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??`
|
|
14
|
-
`)}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
|
|
15
|
-
`)}writeMap(T,U){return T.forEach((O,K)=>U(O,K,this)),this}}class d extends
|
|
14
|
+
`)}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 q)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)):`
|
|
15
|
+
`)}writeMap(T,U){return T.forEach((O,K)=>U(O,K,this)),this}}class d extends q{#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((X,j)=>{let $=X.length;return U.forEach((F)=>{if(F[j])$=Math.max($,F[j].length)}),$}),K=T.map((X,j)=>X.padEnd(O[j]));this.writeLine("| "+K.join(" | ")+" |");let A=O.map((X)=>"-".repeat(X));return this.writeLine("| "+A.join(" | ")+" |"),U.forEach((X)=>{let j=T.map(($,F)=>(X[F]??"").padEnd(O[F]));this.writeLine("| "+j.join(" | ")+" |")}),this}blockquote(T){return T.split(`
|
|
16
16
|
`).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 c{#T;#U;#O=new Map;#K=[];constructor(T,U=[]){this.#T=[...T],this.#U=[...U],this.#$()}get args(){return[...this.#T]}get positionals(){return[...this.#K]}has(T){return this.#O.has(this.#A(T))}getArgs(T){return[...this.#O.get(this.#A(T))?.values??[]]}get(T){let U=this.#O.get(this.#A(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(`
|
|
17
17
|
`);U.push("","Options:");for(let O of this.#U){let K=`--${O.name}`,A=O.alias?`-${O.alias}`:void 0,X=O.valueName??"value",j=O.takesValue?O.multiple?` <${X}...>`:` <${X}>`:"",$=A?`${A}, ${K}`:K,F=O.description?` ${O.description}`:"";U.push(` ${$}${j}${F}`)}return U.join(`
|
|
18
|
-
`)}#$(){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 A=U.indexOf("="),X=this.#A(U.slice(0,A)),j=U.slice(A+1);this.#X(X,j.length>0?[j]:[""],!0);continue}let O=this.#A(U),K=[];while(T+1<this.#T.length){let A=this.#T[T+1];if(A.startsWith("-")&&A!=="-")break;K.push(A),T++}this.#X(O,K,!1)}}#X(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}#A(T){return T.replace(/^-+/,"").trim()}}import P from"fs/promises";var L=async(T)=>{try{return await P.access(T,P.constants.R_OK),!0}catch{return!1}};import W from"path";var R=async(T,U)=>{let O=!W.isAbsolute(T)&&U?["",...U]:[""];for(let K of O){let A=W.join(K,T);if(await L(A))return W.resolve(A)}throw Error(`File not found: "${T}"`)};import r from"fs/promises";import o from"path";var s=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,TU=async(T,U)=>{let O=await R(T,U?.dirs),K=await r.readFile(O,"utf-8"),A=o.dirname(O),X={text:{fn:(F)=>F,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...U?.parsers},j=U?.format?X[U.format]:Object.values(X).find((F)=>s(T,F.matching));if(!j)throw Error(`Unsupported format for file "${T}" and no matching parser found`);return{content:await j.fn(K),fullPath:O,folderPath:A}};import l from"fs/promises";var n=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,S=async(T,U,O)=>{let K={text:{fn:(X)=>X,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...O?.encoders},A=O?.format?K[O.format]:Object.values(K).find((X)=>n(T,X.matching));if(!A)throw Error(`Unsupported format for file "${T}" and no matching encoder found`);await l.writeFile(T,await A.fn(U))};import i from"fs/promises";var XU=async(T,U)=>{if(typeof T==="string"&&!T.includes("*"))return await U.map(T,0,[]);let O=await Array.fromAsync(i.glob(T,{cwd:U.cwd})),K=U.filter?O.filter(U.filter):O;return await Promise.all(K.map(U.map))};import x from"fs/promises";import I from"path";var ZU=async(T,U)=>{if(U?.targetDirectory&&U?.removeFirst)try{await x.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 a(O,U)},a=async(T,U)=>{let O=I.join(U?.targetDirectory??".",T.name),K=I.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 x.mkdir(K,{recursive:!0})}catch(A){throw Error(`Failed to create target directory "${K}" for output "${O}": ${A.message}`,{cause:A})}try{await S(O,T.value,{format:T.type??"text"})}catch(A){throw Error(`Failed to write output "${O}": ${A.message}`,{cause:A})}};import t from"fs/promises";import V from"path";import m from"path";var z=(T)=>T?m.isAbsolute(T)?T:m.join(process.cwd(),T):process.cwd();var e=async(T,U)=>{let O=[];for(let K of T)try{let A=!V.isAbsolute(K)?V.join(z(U?.cwd),K):K;if(U?.filter?.(A)===!1)continue;let X=await import(A);if(U?.resolveDefault==="only"&&!X.default)throw Error(`Module ${K} does not have a default export`);let j=U?.resolveDefault?X.default??X:X,$=U?.map?await U.map(j,K):j;if($!==void 0)O.push($)}catch(A){if(U?.fail?.(K,A)===!1)continue;throw Error(`Failed to import module ${K}: ${A.message??A}`,{cause:A})}return O},
|
|
18
|
+
`)}#$(){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 A=U.indexOf("="),X=this.#A(U.slice(0,A)),j=U.slice(A+1);this.#X(X,j.length>0?[j]:[""],!0);continue}let O=this.#A(U),K=[];while(T+1<this.#T.length){let A=this.#T[T+1];if(A.startsWith("-")&&A!=="-")break;K.push(A),T++}this.#X(O,K,!1)}}#X(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}#A(T){return T.replace(/^-+/,"").trim()}}import P from"fs/promises";var L=async(T)=>{try{return await P.access(T,P.constants.R_OK),!0}catch{return!1}};import W from"path";var R=async(T,U)=>{let O=!W.isAbsolute(T)&&U?["",...U]:[""];for(let K of O){let A=W.join(K,T);if(await L(A))return W.resolve(A)}throw Error(`File not found: "${T}"`)};import r from"fs/promises";import o from"path";var s=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,TU=async(T,U)=>{let O=await R(T,U?.dirs),K=await r.readFile(O,"utf-8"),A=o.dirname(O),X={text:{fn:(F)=>F,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...U?.parsers},j=U?.format?X[U.format]:Object.values(X).find((F)=>s(T,F.matching));if(!j)throw Error(`Unsupported format for file "${T}" and no matching parser found`);return{content:await j.fn(K),fullPath:O,folderPath:A}};import l from"fs/promises";var n=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,S=async(T,U,O)=>{let K={text:{fn:(X)=>X,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...O?.encoders},A=O?.format?K[O.format]:Object.values(K).find((X)=>n(T,X.matching));if(!A)throw Error(`Unsupported format for file "${T}" and no matching encoder found`);await l.writeFile(T,await A.fn(U))};import i from"fs/promises";var XU=async(T,U)=>{if(typeof T==="string"&&!T.includes("*"))return await U.map(T,0,[]);let O=await Array.fromAsync(i.glob(T,{cwd:U.cwd})),K=U.filter?O.filter(U.filter):O;return await Promise.all(K.map(U.map))};import x from"fs/promises";import I from"path";var ZU=async(T,U)=>{if(U?.targetDirectory&&U?.removeFirst)try{await x.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 a(O,U)},a=async(T,U)=>{let O=I.join(U?.targetDirectory??".",T.name),K=I.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 x.mkdir(K,{recursive:!0})}catch(A){throw Error(`Failed to create target directory "${K}" for output "${O}": ${A.message}`,{cause:A})}try{await S(O,T.value,{format:T.type??"text"})}catch(A){throw Error(`Failed to write output "${O}": ${A.message}`,{cause:A})}};import t from"fs/promises";import V from"path";import m from"path";var z=(T)=>T?m.isAbsolute(T)?T:m.join(process.cwd(),T):process.cwd();var e=async(T,U)=>{let O=[];for(let K of T)try{let A=!V.isAbsolute(K)?V.join(z(U?.cwd),K):K;if(U?.filter?.(A)===!1)continue;let X=await import(A);if(U?.resolveDefault==="only"&&!X.default)throw Error(`Module ${K} does not have a default export`);let j=U?.resolveDefault?X.default??X:X,$=U?.map?await U.map(j,K):j;if($!==void 0)O.push($)}catch(A){if(U?.fail?.(K,A)===!1)continue;throw Error(`Failed to import module ${K}: ${A.message??A}`,{cause:A})}return O},yU=async(T,U)=>{let O=[],K=z(U?.cwd);for(let A of T){let X=(await Array.fromAsync(t.glob(A,{cwd:K}))).map((j)=>V.join(K,j));O.push(...await e(X,U))}return O};class TT{#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,A=null,X=!0;for(let j of O){let $;try{$=await j.handler(U,j)}catch(F){K=F,A=j}if(j.calls++,j.mode==="once")j.cleared=!0;if(typeof $==="boolean"){X=$;break}if(K&&j.errorMode!=="continue")break}if(this.#T[T]=O.filter((j)=>!j.cleared),K&&A?.errorMode==="throw")throw K;return X}}export{ZU as writeOutputs,a as writeOutput,S as writeFormat,R as locate,TU as loadFormat,e as importList,yU as importGlob,XU as globMap,z as getCwd,L as exists,q as StringBuilder,H as NavigateResult,h as NavigateAction,d as Markdown,g as Logger,c as CommandLineArgs,TT as AsyncEmitter};
|