@homedev/framework 1.0.5 → 1.0.7
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 +25 -15
- package/dist/index.js +8 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Defines a color value with red, green, and blue components.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare interface ColorValue {
|
|
2
7
|
r: number;
|
|
3
8
|
g: number;
|
|
4
9
|
b: number;
|
|
5
|
-
}
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Parses and queries command-line arguments.
|
|
@@ -190,14 +195,17 @@ export declare interface LoadResult<T> {
|
|
|
190
195
|
export declare const locate: (fileName: string, dirs?: string[]) => Promise<string>;
|
|
191
196
|
|
|
192
197
|
/**
|
|
198
|
+
* Defines a color for log output. Can be a named color, hex string, or RGB string.
|
|
199
|
+
*
|
|
193
200
|
* @public
|
|
194
201
|
*/
|
|
195
|
-
export declare type
|
|
202
|
+
export declare type LogColor = string | ColorValue;
|
|
196
203
|
|
|
197
204
|
/**
|
|
198
205
|
* @public
|
|
199
206
|
*/
|
|
200
207
|
export declare class Logger {
|
|
208
|
+
#private;
|
|
201
209
|
options: LoggerOptions;
|
|
202
210
|
/**
|
|
203
211
|
* Creates a logger with optional configuration overrides.
|
|
@@ -212,13 +220,10 @@ export declare class Logger {
|
|
|
212
220
|
* @param args - Log payload values.
|
|
213
221
|
*/
|
|
214
222
|
write(className: string, ...args: any[]): void;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
* @returns The colored text for console output.
|
|
220
|
-
*/
|
|
221
|
-
color(text: string, color: ColorValue): string;
|
|
223
|
+
onTime(time: string, _className: string): string;
|
|
224
|
+
onClass(className: string): string;
|
|
225
|
+
onElement(element: any, _className: string): string;
|
|
226
|
+
onLog(className: string, ...args: any[]): void;
|
|
222
227
|
/**
|
|
223
228
|
* Writes an INFO level log entry.
|
|
224
229
|
*
|
|
@@ -257,15 +262,17 @@ export declare class Logger {
|
|
|
257
262
|
export declare interface LoggerOptions {
|
|
258
263
|
level: string;
|
|
259
264
|
showClass: boolean;
|
|
260
|
-
useColors: boolean;
|
|
261
265
|
levels: string[];
|
|
262
266
|
timeStamp: boolean;
|
|
263
267
|
timeLocale?: string;
|
|
264
268
|
timeOptions?: Intl.DateTimeFormatOptions;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
+
colors?: {
|
|
270
|
+
default?: LogColor;
|
|
271
|
+
time?: LogColor;
|
|
272
|
+
levels?: Record<string, LogColor>;
|
|
273
|
+
number?: LogColor;
|
|
274
|
+
quoted?: LogColor;
|
|
275
|
+
};
|
|
269
276
|
}
|
|
270
277
|
|
|
271
278
|
/**
|
|
@@ -606,9 +613,12 @@ declare global {
|
|
|
606
613
|
tokenize(from: Record<string, unknown>, tokenizer?: RegExp): string;
|
|
607
614
|
stripIndent(): string;
|
|
608
615
|
toHtmlLink(path?: string): string;
|
|
616
|
+
toHtml(): string;
|
|
609
617
|
toStringBuilder(): StringBuilder;
|
|
610
618
|
toRgb(): string;
|
|
611
619
|
toArgb(): string;
|
|
620
|
+
toColor(defaultColor?: ColorValue): ColorValue;
|
|
621
|
+
colorize(color: string | ColorValue): string;
|
|
612
622
|
single(char: string): string;
|
|
613
623
|
remove(char: string): string;
|
|
614
624
|
toAlphanum(replaceWith?: string): string;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Array.prototype.findOrFail=function(T,U,O){let
|
|
1
|
+
Array.prototype.findOrFail=function(T,U,O){let A=this.find(T,O);if(A===void 0)throw Error(U??"Element not found");return A};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 A=T(O);if(!U[A])U[A]=[];return U[A].push(O),U},{})};Array.prototype.createInstances=function(T,...U){return this.map((O,A)=>new T(...U,O,A))};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 A=T(this[O],O,this);if(A!=null)U.push(A)}return U};Array.prototype.nonNullMapAsync=async function(T){let U=[];for(let O=0;O<this.length;O++){let A=await T(this[O],O,this);if(A!=null)U.push(A)}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 A=T(O),E=U?U(O):O;return[A,E]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((U)=>[String(U[T]),U]))};Array.prototype.selectFor=function(T,U,O,A){let E=this.find(T,A);if(E===void 0)throw Error(O??"Element not found");return U(E)};Array.prototype.sortBy=function(T,U=!0){return this.slice().sort((O,A)=>{let E=T(O),K=T(A);if(E<K)return U?-1:1;if(E>K)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 A=T(O);if(U.has(A))return!1;else return U.add(A),!0})};var P;((X)=>{X[X.Explore=0]="Explore";X[X.SkipSiblings=1]="SkipSiblings";X[X.NoExplore=2]="NoExplore";X[X.ReplaceParent=3]="ReplaceParent";X[X.DeleteParent=4]="DeleteParent";X[X.MergeParent=5]="MergeParent";X[X.ReplaceItem=6]="ReplaceItem";X[X.DeleteItem=7]="DeleteItem"})(P||={});class j{action;by;skipSiblings;reexplore;constructor(T,U,O,A){this.action=T;this.by=U;this.skipSiblings=O;this.reexplore=A}static _explore=new j(0);static _noExplore=new j(2);static _skipSiblings=new j(1);static _deleteParent=new j(4);static ReplaceParent(T,U){return new j(3,T,void 0,U)}static SkipSiblings(){return j._skipSiblings}static Explore(){return j._explore}static NoExplore(){return j._noExplore}static DeleteParent(){return j._deleteParent}static MergeParent(T){return new j(5,T)}static ReplaceItem(T,U){return new j(6,T,U)}static DeleteItem(T){return new j(7,void 0,T)}}Object.navigate=async(T,U)=>{let O=new WeakSet,A=[],E=[],K=async($,X,G)=>{let J=$===null,Q=J?j.Explore():await U({key:$,value:X,path:A,parent:G,parents:E});if(X&&typeof X==="object"&&Q.action===0){if(O.has(X))return Q;if(O.add(X),!J)A.push($),E.push(G);let Z=X;while(await F(Z,$,G))Z=G[$];if(!J)E.pop(),A.pop()}return Q},F=async($,X,G)=>{let J=Object.keys($),Y=J.length;for(let Q=0;Q<Y;Q++){let b=J[Q],H=$[b],Z=await K(b,H,$),_=Z.action;if(_===0||_===2)continue;if(_===6){if($[b]=Z.by,Z.skipSiblings)return;continue}if(_===7){if(delete $[b],Z.skipSiblings)return;continue}if(_===1)return;if(_===3){if(X===null)throw Error("Cannot replace root object");if(G[X]=Z.by,Z.reexplore)return!0;return}if(_===4){if(X===null)throw Error("Cannot delete root object");delete G[X];return}if(_===5)delete $[b],Object.assign($,Z.by)}};await K(null,T,null)};Object.find=async function(T,U){let O=[];return await Object.navigate(T,(A)=>{if(U([...A.path,A.key].join("."),A.value))O.push(A.value);return j.Explore()}),O};Object.merge=(T,U,O)=>{for(let A of Object.keys(U)){if(T[A]===void 0)continue;let E=U[A],K=T[A];if(typeof K!==typeof E||Array.isArray(K)!==Array.isArray(E)){let $=O?.mismatch?.(A,K,E,T,U);if($!==void 0){U[A]=$;continue}throw Error(`Type mismatch: ${A}`)}let F=O?.mode?.(A,K,E,T,U)??U[".merge"]??"merge";switch(F){case"source":U[A]=K;continue;case"target":continue;case"skip":delete U[A],delete T[A];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${F}`)}if(typeof K==="object")if(Array.isArray(K))E.push(...K);else{if(O?.navigate?.(A,K,E,T,U)===!1)continue;Object.merge(K,E,O)}else{if(K===E)continue;let $=O?.conflict?.(A,K,E,T,U);U[A]=$===void 0?E:$}}for(let A of Object.keys(T))if(U[A]===void 0)U[A]=T[A]};var R=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,S=/^([^[\]]*)\[([^\]]*)]$/,D=(T,U,O,A)=>{if(T.startsWith("{")&&T.endsWith("}")){let E=T.substring(1,T.length-1);return Object.select(U,E,O)?.toString()}return A?T:void 0},x=(T,U,O,A)=>{let E=D(U,O,A);if(E)return Object.select(T,E,A);let K=R.exec(U);if(K){let[,$,X,G]=K,J=D($.trim(),O,A,!0),Y=D(G.trim(),O,A,!0);if(Array.isArray(T)&&(X==="="||X==="==")&&J)return T.find((Q)=>Q?.[J]==Y)}let F=S.exec(U);if(F){let[,$,X]=F;return T?.[$]?.[X]}return T?.[U]};Object.select=(T,U,O)=>{let A=void 0,E=void 0,K=U??"",F=(Y)=>{if(!Y)return[Y,!1];return Y.endsWith("?")?[Y.substring(0,Y.length-1),!0]:[Y,!1]},$=(Y,Q)=>{let[b,H]=F(Q.pop());if(!b){if(O?.set!==void 0&&E!==void 0&&A!==void 0)A[E]=O.set;return Y}let Z=x(Y,b,T,O);if(Z===void 0){if(H||O?.optional||O?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${b}" in "${K}"`)}return A=Y,E=b,$(Z,Q)},X=K.splitNested(O?.separator??".","{","}"),G=void 0;if(X.length>0&&X[X.length-1].startsWith("?="))G=X.pop()?.substring(2);X.reverse();let J=$(T,X);if(J===void 0)return G??O?.defaultValue;return J};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,A])=>({[U]:O,...A}))};Object.mapEntries=function(T,U){let A=Object.entries(T).map(([E,K])=>U(E,K));return Object.fromEntries(A)};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};String.prototype.tokenize=function(T,U=/\${([^}]+)}/g){return this.replace(U,(O,A)=>{let E=T[A];if(E===null||E===void 0)return"";if(typeof E==="string")return E;if(typeof E==="number"||typeof E==="boolean")return String(E);return String(E)})};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,A=T.length,E=0,K=(F)=>{if(F+A>O)return!1;for(let $=0;$<A;$++)if(this[F+$]!==T[$])return!1;return!0};while(E<O){while(E<O&&this[E]===" ")E++;if(E>=O)break;let F="",$=this[E]==='"'||this[E]==="'";if($){let X=this[E++];while(E<O&&this[E]!==X)F+=this[E++];if(E<O)E++}else{while(E<O&&!K(E)){let X=this[E];if(X==='"'||X==="'"){F+=X,E++;while(E<O&&this[E]!==X)F+=this[E++];if(E<O)F+=this[E++]}else F+=this[E++]}F=F.trim()}if(F)U.push({value:F,quoted:$});if(K(E))E+=A}return U};String.prototype.splitNested=function(T,U,O){let A=0,E="",K=[];for(let F of this){if(E+=F,F===U)A++;if(F===O)A--;if(A===0&&F===T)K.push(E.slice(0,-1)),E=""}if(E)K.push(E);return K};String.prototype.toStringBuilder=function(){return new B(this.split(`
|
|
2
2
|
`))};String.prototype.padBlock=function(T,U=`
|
|
3
|
-
`,O=" "){let
|
|
4
|
-
`)};String.prototype.toHtmlLink=function(T){return`<a href="${T??this.toString()}">${this.toString()}</a>`};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),
|
|
3
|
+
`,O=" "){let A=O.repeat(T);return this.split(U).map((E)=>A+E).join(U)};String.prototype.stripIndent=function(){let T=this.split(/\r?\n/),U=T.filter((A)=>A.trim().length>0).map((A)=>/^[ \t]*/.exec(A)?.[0].length??0),O=U.length>0?Math.min(...U):0;if(O===0)return this;return T.map((A)=>A.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),A=parseInt(T.substring(4,6),16);return`rgb(${U.toString()}, ${O.toString()}, ${A.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),A=parseInt(T.substring(4,6),16),E=parseInt(T.substring(6,8),16);return`argb(${U.toString()}, ${O.toString()}, ${A.toString()}, ${E.toString()})`};var W={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,A,E;if(W[U])U=W[U];if(U.startsWith("#")){let K=U.slice(1);if(K.length===3)O=parseInt(K[0]+K[0],16),A=parseInt(K[1]+K[1],16),E=parseInt(K[2]+K[2],16);else if(K.length===6)O=parseInt(K.slice(0,2),16),A=parseInt(K.slice(2,4),16),E=parseInt(K.slice(4,6),16);else{if(T)return T;throw Error(`Invalid hex color: ${U}`)}return{r:O,g:A,b:E}}if(U.includes(";")){let K=U.split(";").map(Number);if(K.length!==3||K.some(isNaN)){if(T)return T;throw Error(`Invalid RGB color string: ${U}`)}return{r:K[0],g:K[1],b:K[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 E=this.options.levels.indexOf(this.options.level),K=this.options.levels.indexOf(T);if(E===-1)throw Error(`Unknown configured log level: ${this.options.level}`);if(K===-1)throw Error(`Unknown log level: ${T}`);if(K<E)return}let O=[],A=[];if(this.options.timeStamp)A.push(this.onTime(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions),T));if(this.options.showClass)A.push(this.onClass(T));if(A.length>0)O.push(`[${A.join(" ")}]`);O.push(...U.map((E)=>this.onElement(E,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.#A(T.toString(),this.options.colors?.number);if(typeof T==="string")return this.#X(T,this.options.colors?.default);return T}#A(T,U){if(!U)return T;return T.colorize(U)}#X(T,U){let O=[],A=0;while(A<T.length){let E=this.#K(T,A,this.#T,"quoted"),K=this.#K(T,A,this.#U,"color"),F=this.#K(T,A,this.#O,"number"),$=this.#E(E,K,F);if(!$){O.push(this.#A(T.slice(A),U));break}if($.index>A)O.push(this.#A(T.slice(A,$.index),U));if($.kind==="quoted")O.push(this.#A($.match[0],this.options.colors?.quoted));else if($.kind==="number")O.push(this.#A($.match[0],this.options.colors?.number));else{let X=$.match[2]??"";O.push(this.#X(X,$.match[1]))}A=$.index+$.match[0].length}return O.join("")}#K(T,U,O,A){let E=new RegExp(O.source,O.flags);E.lastIndex=U;let K=E.exec(T);if(!K)return null;return{index:K.index,match:K,kind:A}}#E(T,U,O){let A=[T,U,O].filter((E)=>E!==null);if(A.length===0)return null;return A.reduce((E,K)=>K.index<E.index?K:E)}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 B{#T=[];#U=0;options;constructor(T,U){if(T instanceof B)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,
|
|
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,
|
|
10
|
-
`);U.push("","Options:");for(let O of this.#U){let
|
|
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 B)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,A)=>U(O,A,this)),this}}class k extends B{#T=0;#U="```";#O(T){return Math.min(6,Math.max(1,Math.floor(T)))}#A(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.#A(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((K,F)=>{let $=K.length;return U.forEach((X)=>{if(X[F])$=Math.max($,X[F].length)}),$}),A=T.map((K,F)=>K.padEnd(O[F]));this.writeLine("| "+A.join(" | ")+" |");let E=O.map((K)=>"-".repeat(K));return this.writeLine("| "+E.join(" | ")+" |"),U.forEach((K)=>{let F=T.map(($,X)=>(K[X]??"").padEnd(O[X]));this.writeLine("| "+F.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,A)=>this.writeLine(`${(A+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;#A=[];constructor(T,U=[]){this.#T=[...T],this.#U=[...U],this.#X()}get args(){return[...this.#T]}get positionals(){return[...this.#A]}has(T){return this.#O.has(this.#E(T))}getArgs(T){return[...this.#O.get(this.#E(T))?.values??[]]}get(T){let U=this.#O.get(this.#E(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.#A.length>0)U[0]+=" [values]";if(this.#U.length===0)return U.join(`
|
|
10
|
+
`);U.push("","Options:");for(let O of this.#U){let A=`--${O.name}`,E=O.alias?`-${O.alias}`:void 0,K=O.valueName??"value",F=O.takesValue?O.multiple?` <${K}...>`:` <${K}>`:"",$=E?`${E}, ${A}`:A,X=O.description?` ${O.description}`:"";U.push(` ${$}${F}${X}`)}return U.join(`
|
|
11
|
+
`)}#X(){for(let T=0;T<this.#T.length;T++){let U=this.#T[T];if(!U.startsWith("-")||U==="-"){this.#A.push(U);continue}if(U.startsWith("--")&&U.includes("=")){let E=U.indexOf("="),K=this.#E(U.slice(0,E)),F=U.slice(E+1);this.#K(K,F.length>0?[F]:[""],!0);continue}let O=this.#E(U),A=[];while(T+1<this.#T.length){let E=this.#T[T+1];if(E.startsWith("-")&&E!=="-")break;A.push(E),T++}this.#K(O,A,!1)}}#K(T,U,O){let A=this.#O.get(T);if(!A){this.#O.set(T,{values:[...U],sawEqualsStyle:O});return}A.values.push(...U),A.sawEqualsStyle=A.sawEqualsStyle||O}#E(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 A of O){let E=q.join(A,T);if(await C(E))return q.resolve(E)}throw Error(`File not found: "${T}"`)};import d from"fs/promises";import v from"path";var h=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,uT=async(T,U)=>{let O=await L(T,U?.dirs),A=await d.readFile(O,"utf-8"),E=v.dirname(O),K={text:{fn:(X)=>X,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.parse,matching:["\\.json$"]},...U?.parsers},F=U?.format?K[U.format]:Object.values(K).find((X)=>h(T,X.matching));if(!F)throw Error(`Unsupported format for file "${T}" and no matching parser found`);return{content:await F.fn(A),fullPath:O,folderPath:E}};import p from"fs/promises";var g=(T,U)=>U?.some((O)=>new RegExp(O).test(T))===!0,V=async(T,U,O)=>{let A={text:{fn:(K)=>K,matching:["\\.txt$","\\.text$"]},json:{fn:JSON.stringify,matching:["\\.json$"]},...O?.encoders},E=O?.format?A[O.format]:Object.values(A).find((K)=>g(T,K.matching));if(!E)throw Error(`Unsupported format for file "${T}" and no matching encoder found`);await p.writeFile(T,await E.fn(U))};import u from"fs/promises";var sT=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})),A=U.filter?O.filter(U.filter):O;return await Promise.all(A.map(U.map))};import w from"fs/promises";import f from"path";var eT=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=f.join(U?.targetDirectory??".",T.name),A=f.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(A,{recursive:!0})}catch(E){throw Error(`Failed to create target directory "${A}" for output "${O}": ${E.message}`,{cause:E})}try{await V(O,T.value,{format:T.type??"text"})}catch(E){throw Error(`Failed to write output "${O}": ${E.message}`,{cause:E})}};import r from"fs/promises";import y from"path";import M from"path";var I=(T)=>T?M.isAbsolute(T)?T:M.join(process.cwd(),T):process.cwd();var n=async(T,U)=>{let O=[];for(let A of T)try{let E=!y.isAbsolute(A)?y.join(I(U?.cwd),A):A;if(U?.filter?.(E)===!1)continue;let K=await import(E);if(U?.resolveDefault==="only"&&!K.default)throw Error(`Module ${A} does not have a default export`);let F=U?.resolveDefault?K.default??K:K,$=U?.map?await U.map(F,A):F;if($!==void 0)O.push($)}catch(E){if(U?.fail?.(A,E)===!1)continue;throw Error(`Failed to import module ${A}: ${E.message??E}`,{cause:E})}return O},XU=async(T,U)=>{let O=[],A=I(U?.cwd);for(let E of T){let K=(await Array.fromAsync(r.glob(E,{cwd:A}))).map((F)=>y.join(A,F));O.push(...await n(K,U))}return O};export{eT as writeOutputs,c as writeOutput,V as writeFormat,L as locate,uT as loadFormat,n as importList,XU as importGlob,sT as globMap,I as getCwd,C as exists,B as StringBuilder,j as NavigateResult,P as NavigateAction,k as Markdown,m as Logger,N as CommandLineArgs};
|