@homedev/framework 0.0.7 → 0.0.9

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 CHANGED
@@ -1,25 +1,3 @@
1
- /**
2
- * Guards against undefined and null values.
3
- * Throws an error if the value is nullish, otherwise returns the value.
4
- *
5
- * @param value - The value to check
6
- * @param message - Custom error message (default: 'Value is undefined')
7
- * @returns The value if it is not nullish
8
- * @throws {Error} When value is undefined or null
9
- *
10
- * @example
11
- * ```typescript
12
- * const value = defined(maybeUndefined, 'Required value missing')
13
- * // value is guaranteed to be non-nullish here
14
- *
15
- * defined(0) // 0 (falsy but not nullish)
16
- * defined(false) // false (falsy but not nullish)
17
- * defined(null) // throws Error: Value is undefined
18
- * ```
19
- */
20
- declare function defined_2<T>(value: T | undefined | null, message?: string): T;
21
- export { defined_2 as defined }
22
-
23
1
  export declare type LogFunction = (className: string, ...args: any[]) => void;
24
2
 
25
3
  export declare class Logger {
@@ -46,14 +24,15 @@ export declare interface LoggerOptions {
46
24
  export declare class Markdown extends StringBuilder {
47
25
  #private;
48
26
  header(text: string, level?: number): this;
49
- codeBlock(code: string, language?: string): this;
27
+ codeBlock(code?: string, language?: string): this;
28
+ endCodeBlock(): this;
50
29
  link(text: string, url: string): this;
51
30
  table(headers: string[], rows: string[][]): this;
52
31
  blockquote(text: string): this;
53
32
  bold(text: string): this;
54
33
  italic(text: string): this;
55
34
  item(text: string): this;
56
- list(items: string[]): this;
35
+ items(items: string[]): this;
57
36
  orderedList(items: string[], start?: number): this;
58
37
  code(text: string): this;
59
38
  horizontalRule(): this;
@@ -158,12 +137,29 @@ export declare interface SelectOptions {
158
137
 
159
138
  export declare class StringBuilder {
160
139
  #private;
161
- constructor(initial?: string | string[]);
162
- append(...args: any[]): this;
163
- appendLine(...args: any[]): this;
140
+ options: StringBuilderOptions;
141
+ constructor(initial?: string | string[] | StringBuilder, options?: StringBuilderOptions);
142
+ setOptions(options: StringBuilderOptions): this;
164
143
  clear(): this;
165
144
  isEmpty(): boolean;
166
145
  toString(): string;
146
+ indent(): this;
147
+ dedent(): this;
148
+ getCurrentIndent(): number;
149
+ getLines(): string[];
150
+ formatLine(line: string): string;
151
+ write(...args: any[]): this;
152
+ writeLine(...args: any[]): this;
153
+ writeMap<T>(items: T[], fn: (item: T, index: number, builder: StringBuilder) => string | StringBuilder): this;
154
+ }
155
+
156
+ export declare interface StringBuilderOptions {
157
+ indentChar?: string;
158
+ indentSize?: number;
159
+ trim?: boolean;
160
+ lineSeparator?: string;
161
+ linePrefix?: string;
162
+ lineSuffix?: string;
167
163
  }
168
164
 
169
165
  export { }
@@ -178,6 +174,18 @@ declare global {
178
174
  var defined: <T>(value: T | undefined | null, msg?: string) => T;
179
175
  }
180
176
 
177
+ declare global {
178
+ interface ObjectConstructor {
179
+ mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
180
+ toList<T extends object, U extends object, X extends string>(obj: T, key: X): (Record<X, string> & U)[];
181
+ deepClone<T extends object>(obj: T): T;
182
+ merge(source: any, target: any, options?: MergeOptions): void;
183
+ navigate(o: any, cb: NavigateCallback): Promise<void>;
184
+ find(from: any, cb: (path: string, value: any) => boolean): Promise<any[]>;
185
+ select(from: any, path: string, options?: SelectOptions): any;
186
+ }
187
+ }
188
+
181
189
  declare global {
182
190
  interface Array<T> {
183
191
  mapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
@@ -200,18 +208,6 @@ declare global {
200
208
  }
201
209
  }
202
210
 
203
- declare global {
204
- interface ObjectConstructor {
205
- mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
206
- toList<T extends object, U extends object, X extends string>(obj: T, key: X): (Record<X, string> & U)[];
207
- deepClone<T extends object>(obj: T): T;
208
- merge(source: any, target: any, options?: MergeOptions): void;
209
- navigate(o: any, cb: NavigateCallback): Promise<void>;
210
- find(from: any, cb: (path: string, value: any) => boolean): Promise<any[]>;
211
- select(from: any, path: string, options?: SelectOptions): any;
212
- }
213
- }
214
-
215
211
  declare global {
216
212
  interface String {
217
213
  capitalize(): string;
@@ -230,6 +226,14 @@ declare global {
230
226
  stripIndent(): string;
231
227
  toHtmlLink(path?: string): string;
232
228
  toStringBuilder(): StringBuilder;
229
+ toRgb(): string;
230
+ toArgb(): string;
231
+ single(char: string): string;
232
+ ltrim(): string;
233
+ rtrim(): string;
234
+ remove(char: string): string;
235
+ toAlphanum(): string;
236
+ toAlpha(): string;
233
237
  }
234
238
  }
235
239
 
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
- Array.prototype.findOrFail=function(n,r,t){let s=this.find(n,t);if(s===void 0)throw Error(r??"Element not found");return s};Array.flat=function(n){if(Array.isArray(n))return n.flat(2);else return[n]};Array.prototype.forEachAsync=async function(n){for(let r=0;r<this.length;r++)await n(this[r],r,this)};Array.prototype.groupBy=function(n){return this.reduce((r,t)=>{let s=n(t);if(!r[s])r[s]=[];return r[s].push(t),r},{})};Array.prototype.createInstances=function(n,...r){return this.map((t,s)=>new n(...r,t,s))};Array.prototype.mapAsync=async function(n){return Promise.all(this.map(n))};Array.prototype.nonNullMap=function(n){let r=[];for(let t=0;t<this.length;t++){let s=n(this[t],t,this);if(s!=null)r.push(s)}return r};Array.prototype.nonNullMapAsync=async function(n){let r=[];for(let t=0;t<this.length;t++){let s=await n(this[t],t,this);if(s!=null)r.push(s)}return r};Array.prototype.mergeAll=function(n){let r={};for(let t of this.toReversed())Object.merge(t,r,n);return r};Array.prototype.toObject=function(n,r){return Object.fromEntries(this.map((t)=>{let s=n(t),o=r?r(t):t;return[s,o]}))};Array.prototype.toObjectWithKey=function(n){return Object.fromEntries(this.map((r)=>[String(r[n]),r]))};Array.prototype.selectFor=function(n,r,t,s){let o=this.find(n,s);if(o===void 0)throw Error(t??"Element not found");return r(o)};Array.prototype.sortBy=function(n,r=!0){return this.slice().sort((t,s)=>{let o=n(t),e=n(s);if(o<e)return r?-1:1;if(o>e)return r?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(n){let r=new Set;return this.filter((t)=>{let s=n(t);if(r.has(s))return!1;else return r.add(s),!0})};var E;((i)=>{i[i.Explore=0]="Explore";i[i.SkipSiblings=1]="SkipSiblings";i[i.NoExplore=2]="NoExplore";i[i.ReplaceParent=3]="ReplaceParent";i[i.DeleteParent=4]="DeleteParent";i[i.MergeParent=5]="MergeParent";i[i.ReplaceItem=6]="ReplaceItem";i[i.DeleteItem=7]="DeleteItem"})(E||={});class T{action;by;skipSiblings;reexplore;constructor(n,r,t,s){this.action=n;this.by=r;this.skipSiblings=t;this.reexplore=s}static _explore=new T(0);static _noExplore=new T(2);static _skipSiblings=new T(1);static _deleteParent=new T(4);static ReplaceParent(n,r){return new T(3,n,void 0,r)}static SkipSiblings(){return T._skipSiblings}static Explore(){return T._explore}static NoExplore(){return T._noExplore}static DeleteParent(){return T._deleteParent}static MergeParent(n){return new T(5,n)}static ReplaceItem(n,r){return new T(6,n,r)}static DeleteItem(n){return new T(7,void 0,n)}}Object.navigate=async(n,r)=>{let t=new WeakSet,s=[],o=[],e=async(d,i,p)=>{let x=d===null,a=x?T.Explore():await r({key:d,value:i,path:s,parent:p,parents:o});if(i&&typeof i==="object"&&a.action===0){if(t.has(i))return a;if(t.add(i),!x)s.push(d),o.push(p);let m=i;while(await h(m,d,p))m=p[d];if(!x)o.pop(),s.pop()}return a},h=async(d,i,p)=>{let x=Object.keys(d),f=x.length;for(let a=0;a<f;a++){let g=x[a],c=d[g],m=await e(g,c,d),b=m.action;if(b===0||b===2)continue;if(b===6){if(d[g]=m.by,m.skipSiblings)return;continue}if(b===7){if(delete d[g],m.skipSiblings)return;continue}if(b===1)return;if(b===3){if(i===null)throw Error("Cannot replace root object");if(p[i]=m.by,m.reexplore)return!0;return}if(b===4){if(i===null)throw Error("Cannot delete root object");delete p[i];return}if(b===5)delete d[g],Object.assign(d,m.by)}};await e(null,n,null)};Object.find=async function(n,r){let t=[];return await Object.navigate(n,(s)=>{if(r([...s.path,s.key].join("."),s.value))t.push(s.value);return T.Explore()}),t};Object.merge=(n,r,t)=>{for(let s of Object.keys(r)){if(n[s]===void 0)continue;let o=r[s],e=n[s];if(typeof e!==typeof o||Array.isArray(e)!==Array.isArray(o)){let d=t?.mismatch?.(s,e,o,n,r);if(d!==void 0){r[s]=d;continue}throw Error(`Type mismatch: ${s}`)}let h=t?.mode?.(s,e,o,n,r)??r[".merge"]??"merge";switch(h){case"source":r[s]=e;continue;case"target":continue;case"skip":delete r[s],delete n[s];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${h}`)}if(typeof e==="object")if(Array.isArray(e))o.push(...e);else{if(t?.navigate?.(s,e,o,n,r)===!1)continue;Object.merge(e,o,t)}else{if(e===o)continue;let d=t?.conflict?.(s,e,o,n,r);r[s]=d===void 0?o:d}}for(let s of Object.keys(n))if(r[s]===void 0)r[s]=n[s]};var O=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,F=/^([^[\]]*)\[([^\]]*)]$/,w=(n,r,t,s)=>{if(n.startsWith("{")&&n.endsWith("}")){let o=n.substring(1,n.length-1);return Object.select(r,o,t)?.toString()}return s?n:void 0},U=(n,r,t,s)=>{let o=w(r,t,s);if(o)return Object.select(n,o,s);let e=O.exec(r);if(e){let[,d,i,p]=e,x=w(d.trim(),t,s,!0),f=w(p.trim(),t,s,!0);if(Array.isArray(n)&&(i==="="||i==="==")&&x)return n.find((a)=>a?.[x]==f)}let h=F.exec(r);if(h){let[,d,i]=h;return n?.[d]?.[i]}return n?.[r]};Object.select=(n,r,t)=>{let s=void 0,o=void 0,e=r??"",h=(f)=>{if(!f)return[f,!1];return f.endsWith("?")?[f.substring(0,f.length-1),!0]:[f,!1]},d=(f,a)=>{let[g,c]=h(a.pop());if(!g){if(t?.set!==void 0&&o!==void 0&&s!==void 0)s[o]=t.set;return f}let m=U(f,g,n,t);if(m===void 0){if(c||t?.optional||t?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${g}" in "${e}"`)}return s=f,o=g,d(m,a)},i=e.splitNested(t?.separator??".","{","}"),p=void 0;if(i.length>0&&i[i.length-1].startsWith("?="))p=i.pop()?.substring(2);i.reverse();let x=d(n,i);if(x===void 0)return p??t?.defaultValue;return x};Object.deepClone=function(n){if(typeof structuredClone<"u")try{return structuredClone(n)}catch{}return JSON.parse(JSON.stringify(n))};Object.toList=function(n,r){return Object.entries(n).map(([t,s])=>({[r]:t,...s}))};Object.mapEntries=function(n,r){let s=Object.entries(n).map(([o,e])=>r(o,e));return Object.fromEntries(s)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(n,r="Value is undefined")=>{if(n===void 0||n===null)throw Error(r);return n};String.prototype.tokenize=function(n,r=/\${([^}]+)}/g){return this.replace(r,(t,s)=>{let o=n[s];if(o===null||o===void 0)return"";if(typeof o==="string")return o;if(typeof o==="number"||typeof o==="boolean")return String(o);return String(o)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(n,r)=>r.toUpperCase()).replace(/[^a-zA-Z0-9 ]/g,"").replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(n,r)=>r.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(n,r)=>r.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(n){switch(n){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: ${n}`)}};String.prototype.splitWithQuotes=function(n=","){let r=[],t=this.length,s=n.length,o=0,e=(h)=>{if(h+s>t)return!1;for(let d=0;d<s;d++)if(this[h+d]!==n[d])return!1;return!0};while(o<t){while(o<t&&this[o]===" ")o++;if(o>=t)break;let h="",d=this[o]==='"'||this[o]==="'";if(d){let i=this[o++];while(o<t&&this[o]!==i)h+=this[o++];if(o<t)o++}else{while(o<t&&!e(o)){let i=this[o];if(i==='"'||i==="'"){h+=i,o++;while(o<t&&this[o]!==i)h+=this[o++];if(o<t)h+=this[o++]}else h+=this[o++]}h=h.trim()}if(h)r.push({value:h,quoted:d});if(e(o))o+=s}return r};String.prototype.splitNested=function(n,r,t){let s=0,o="",e=[];for(let h of this){if(o+=h,h===r)s++;if(h===t)s--;if(s===0&&h===n)e.push(o.slice(0,-1)),o=""}if(o)e.push(o);return e};String.prototype.toStringBuilder=function(){return new u(this.split(`
2
- `))};String.prototype.padBlock=function(n,r=`
3
- `,t=" "){let s=t.repeat(n);return this.split(r).map((o)=>s+o).join(r)};String.prototype.stripIndent=function(){let n=this.split(/\r?\n/),r=n.filter((s)=>s.trim().length>0).map((s)=>/^[ \t]*/.exec(s)?.[0].length??0),t=r.length>0?Math.min(...r):0;if(t===0)return this;return n.map((s)=>s.slice(t)).join(`
4
- `)};String.prototype.toHtmlLink=function(n){return`<a href="${n??this.toString()}">${this.toString()}</a>`};function v(n,r="Value is undefined"){if(n===void 0||n===null)throw Error(r);return n}class L{options;constructor(n){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"},logFunction:(r,...t)=>{switch(r){case"ERROR":console.error(...t);break;case"WARN":console.warn(...t);break;case"DEBUG":console.debug(...t);break;case"VERBOSE":console.log(...t);break;default:console.log(...t)}},...n}}write(n,...r){if(this.options.level){let o=this.options.levels.indexOf(this.options.level)??-1,e=this.options.levels.indexOf(n);if(e===-1)throw Error(`Unknown log level: ${n}`);if(e<o)return}let t=[],s=[];if(this.options.timeStamp)s.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)s.push(n);if(s.length>0)t.push(`[${s.join(" ")}]`);t.push(...r),this.options.logFunction(n,...t)}info(...n){this.write("INFO",...n)}error(...n){this.write("ERROR",...n)}warn(...n){this.write("WARN",...n)}debug(...n){this.write("DEBUG",...n)}verbose(...n){this.write("VERBOSE",...n)}}class u{#n=[];constructor(n){if(n)if(Array.isArray(n))this.#n.push(...n);else this.#n.push(n)}append(...n){return this.#n.push(...n),this}appendLine(...n){return this.append(...n.map((r)=>{if(r===null||r===void 0)return`
5
- `;return`${r.toString()}
6
- `})),this}clear(){return this.#n.length=0,this}isEmpty(){return this.#n.length===0}toString(){return this.#n.join("")}}class $ extends u{header(n,r=1){return this.appendLine(`${"#".repeat(r)} ${n}`)}codeBlock(n,r=""){return this.appendLine(`\`\`\`${r}
7
- ${n}
8
- \`\`\``)}link(n,r){return this.append(`[${n}](${r})`)}table(n,r){let t=n.map((e,h)=>{let d=e.length;return r.forEach((i)=>{if(i[h])d=Math.max(d,i[h].length)}),d}),s=n.map((e,h)=>e.padEnd(t[h]));this.appendLine("| "+s.join(" | ")+" |");let o=t.map((e)=>"-".repeat(e));return this.appendLine("| "+o.join(" | ")+" |"),r.forEach((e)=>{let h=e.map((d,i)=>d.padEnd(t[i]));this.appendLine("| "+h.join(" | ")+" |")}),this}blockquote(n){let r=n.split(`
9
- `);this.appendLine("> "+r[0]);for(let t=1;t<r.length;t++)this.appendLine("> "+r[t]);return this}bold(n){return this.append(`**${n}**`)}italic(n){return this.append(`*${n}*`)}item(n){return this.appendLine(`- ${n}`)}list(n){return n.forEach((r)=>this.item(r)),this}orderedList(n,r=1){return n.forEach((t,s)=>this.appendLine(`${(s+r).toString()}. ${t}`)),this}code(n){return this.append(`\`${n}\``)}horizontalRule(){return this.appendLine("---")}image(n,r){return this.appendLine(`![${n}](${r})`)}strikethrough(n){return this.append(`~~${n}~~`)}highlight(n){return this.append(`==${n}==`)}subscript(n){return this.append(`~${n}~`)}superscript(n){return this.append(`^${n}^`)}taskList(n){return n.forEach((r)=>this.appendLine(`- [${r.checked?"x":" "}] ${r.text}`)),this}#n=0;section(n){return this.#n++,this.header(n,this.#n)}endSection(){if(this.#n>0)this.#n--;return this}setSectionLevel(n){return this.#n=n,this}}export{v as defined,u as StringBuilder,T as NavigateResult,E as NavigateAction,$ as Markdown,L as Logger};
1
+ Array.prototype.findOrFail=function(t,r,n){let i=this.find(t,n);if(i===void 0)throw Error(r??"Element not found");return i};Array.flat=function(t){if(Array.isArray(t))return t.flat(2);else return[t]};Array.prototype.forEachAsync=async function(t){for(let r=0;r<this.length;r++)await t(this[r],r,this)};Array.prototype.groupBy=function(t){return this.reduce((r,n)=>{let i=t(n);if(!r[i])r[i]=[];return r[i].push(n),r},{})};Array.prototype.createInstances=function(t,...r){return this.map((n,i)=>new t(...r,n,i))};Array.prototype.mapAsync=async function(t){return Promise.all(this.map(t))};Array.prototype.nonNullMap=function(t){let r=[];for(let n=0;n<this.length;n++){let i=t(this[n],n,this);if(i!=null)r.push(i)}return r};Array.prototype.nonNullMapAsync=async function(t){let r=[];for(let n=0;n<this.length;n++){let i=await t(this[n],n,this);if(i!=null)r.push(i)}return r};Array.prototype.mergeAll=function(t){let r={};for(let n of this.toReversed())Object.merge(n,r,t);return r};Array.prototype.toObject=function(t,r){return Object.fromEntries(this.map((n)=>{let i=t(n),s=r?r(n):n;return[i,s]}))};Array.prototype.toObjectWithKey=function(t){return Object.fromEntries(this.map((r)=>[String(r[t]),r]))};Array.prototype.selectFor=function(t,r,n,i){let s=this.find(t,i);if(s===void 0)throw Error(n??"Element not found");return r(s)};Array.prototype.sortBy=function(t,r=!0){return this.slice().sort((n,i)=>{let s=t(n),e=t(i);if(s<e)return r?-1:1;if(s>e)return r?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(t){let r=new Set;return this.filter((n)=>{let i=t(n);if(r.has(i))return!1;else return r.add(i),!0})};var E;((o)=>{o[o.Explore=0]="Explore";o[o.SkipSiblings=1]="SkipSiblings";o[o.NoExplore=2]="NoExplore";o[o.ReplaceParent=3]="ReplaceParent";o[o.DeleteParent=4]="DeleteParent";o[o.MergeParent=5]="MergeParent";o[o.ReplaceItem=6]="ReplaceItem";o[o.DeleteItem=7]="DeleteItem"})(E||={});class m{action;by;skipSiblings;reexplore;constructor(t,r,n,i){this.action=t;this.by=r;this.skipSiblings=n;this.reexplore=i}static _explore=new m(0);static _noExplore=new m(2);static _skipSiblings=new m(1);static _deleteParent=new m(4);static ReplaceParent(t,r){return new m(3,t,void 0,r)}static SkipSiblings(){return m._skipSiblings}static Explore(){return m._explore}static NoExplore(){return m._noExplore}static DeleteParent(){return m._deleteParent}static MergeParent(t){return new m(5,t)}static ReplaceItem(t,r){return new m(6,t,r)}static DeleteItem(t){return new m(7,void 0,t)}}Object.navigate=async(t,r)=>{let n=new WeakSet,i=[],s=[],e=async(h,o,d)=>{let p=h===null,x=p?m.Explore():await r({key:h,value:o,path:i,parent:d,parents:s});if(o&&typeof o==="object"&&x.action===0){if(n.has(o))return x;if(n.add(o),!p)i.push(h),s.push(d);let g=o;while(await f(g,h,d))g=d[h];if(!p)s.pop(),i.pop()}return x},f=async(h,o,d)=>{let p=Object.keys(h),T=p.length;for(let x=0;x<T;x++){let c=p[x],w=h[c],g=await e(c,w,h),b=g.action;if(b===0||b===2)continue;if(b===6){if(h[c]=g.by,g.skipSiblings)return;continue}if(b===7){if(delete h[c],g.skipSiblings)return;continue}if(b===1)return;if(b===3){if(o===null)throw Error("Cannot replace root object");if(d[o]=g.by,g.reexplore)return!0;return}if(b===4){if(o===null)throw Error("Cannot delete root object");delete d[o];return}if(b===5)delete h[c],Object.assign(h,g.by)}};await e(null,t,null)};Object.find=async function(t,r){let n=[];return await Object.navigate(t,(i)=>{if(r([...i.path,i.key].join("."),i.value))n.push(i.value);return m.Explore()}),n};Object.merge=(t,r,n)=>{for(let i of Object.keys(r)){if(t[i]===void 0)continue;let s=r[i],e=t[i];if(typeof e!==typeof s||Array.isArray(e)!==Array.isArray(s)){let h=n?.mismatch?.(i,e,s,t,r);if(h!==void 0){r[i]=h;continue}throw Error(`Type mismatch: ${i}`)}let f=n?.mode?.(i,e,s,t,r)??r[".merge"]??"merge";switch(f){case"source":r[i]=e;continue;case"target":continue;case"skip":delete r[i],delete t[i];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${f}`)}if(typeof e==="object")if(Array.isArray(e))s.push(...e);else{if(n?.navigate?.(i,e,s,t,r)===!1)continue;Object.merge(e,s,n)}else{if(e===s)continue;let h=n?.conflict?.(i,e,s,t,r);r[i]=h===void 0?s:h}}for(let i of Object.keys(t))if(r[i]===void 0)r[i]=t[i]};var O=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,S=/^([^[\]]*)\[([^\]]*)]$/,a=(t,r,n,i)=>{if(t.startsWith("{")&&t.endsWith("}")){let s=t.substring(1,t.length-1);return Object.select(r,s,n)?.toString()}return i?t:void 0},$=(t,r,n,i)=>{let s=a(r,n,i);if(s)return Object.select(t,s,i);let e=O.exec(r);if(e){let[,h,o,d]=e,p=a(h.trim(),n,i,!0),T=a(d.trim(),n,i,!0);if(Array.isArray(t)&&(o==="="||o==="==")&&p)return t.find((x)=>x?.[p]==T)}let f=S.exec(r);if(f){let[,h,o]=f;return t?.[h]?.[o]}return t?.[r]};Object.select=(t,r,n)=>{let i=void 0,s=void 0,e=r??"",f=(T)=>{if(!T)return[T,!1];return T.endsWith("?")?[T.substring(0,T.length-1),!0]:[T,!1]},h=(T,x)=>{let[c,w]=f(x.pop());if(!c){if(n?.set!==void 0&&s!==void 0&&i!==void 0)i[s]=n.set;return T}let g=$(T,c,t,n);if(g===void 0){if(w||n?.optional||n?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${c}" in "${e}"`)}return i=T,s=c,h(g,x)},o=e.splitNested(n?.separator??".","{","}"),d=void 0;if(o.length>0&&o[o.length-1].startsWith("?="))d=o.pop()?.substring(2);o.reverse();let p=h(t,o);if(p===void 0)return d??n?.defaultValue;return p};Object.deepClone=function(t){if(typeof structuredClone<"u")try{return structuredClone(t)}catch{}return JSON.parse(JSON.stringify(t))};Object.toList=function(t,r){return Object.entries(t).map(([n,i])=>({[r]:n,...i}))};Object.mapEntries=function(t,r){let i=Object.entries(t).map(([s,e])=>r(s,e));return Object.fromEntries(i)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(t,r="Value is undefined")=>{if(t===void 0||t===null)throw Error(r);return t};String.prototype.tokenize=function(t,r=/\${([^}]+)}/g){return this.replace(r,(n,i)=>{let s=t[i];if(s===null||s===void 0)return"";if(typeof s==="string")return s;if(typeof s==="number"||typeof s==="boolean")return String(s);return String(s)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(t,r)=>r.toUpperCase()).replace(/[^a-zA-Z0-9 ]/g,"").replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(t,r)=>r.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(t,r)=>r.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 r=[],n=this.length,i=t.length,s=0,e=(f)=>{if(f+i>n)return!1;for(let h=0;h<i;h++)if(this[f+h]!==t[h])return!1;return!0};while(s<n){while(s<n&&this[s]===" ")s++;if(s>=n)break;let f="",h=this[s]==='"'||this[s]==="'";if(h){let o=this[s++];while(s<n&&this[s]!==o)f+=this[s++];if(s<n)s++}else{while(s<n&&!e(s)){let o=this[s];if(o==='"'||o==="'"){f+=o,s++;while(s<n&&this[s]!==o)f+=this[s++];if(s<n)f+=this[s++]}else f+=this[s++]}f=f.trim()}if(f)r.push({value:f,quoted:h});if(e(s))s+=i}return r};String.prototype.splitNested=function(t,r,n){let i=0,s="",e=[];for(let f of this){if(s+=f,f===r)i++;if(f===n)i--;if(i===0&&f===t)e.push(s.slice(0,-1)),s=""}if(s)e.push(s);return e};String.prototype.toStringBuilder=function(){return new u(this.split(`
2
+ `))};String.prototype.padBlock=function(t,r=`
3
+ `,n=" "){let i=n.repeat(t);return this.split(r).map((s)=>i+s).join(r)};String.prototype.stripIndent=function(){let t=this.split(/\r?\n/),r=t.filter((i)=>i.trim().length>0).map((i)=>/^[ \t]*/.exec(i)?.[0].length??0),n=r.length>0?Math.min(...r):0;if(n===0)return this;return t.map((i)=>i.slice(n)).join(`
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 r=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return`rgb(${r.toString()}, ${n.toString()}, ${i.toString()})`};String.prototype.toArgb=function(){let t=this.toString().replace("#","");if(t.length!==8)throw Error("Invalid hex color");let r=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16),s=parseInt(t.substring(6,8),16);return`argb(${r.toString()}, ${n.toString()}, ${i.toString()}, ${s.toString()})`};String.prototype.single=function(t){return this.replaceAll(new RegExp(`(${t})+`,"g"),"$1")};String.prototype.ltrim=function(){return this.replace(/^\s+/,"")};String.prototype.rtrim=function(){return this.replace(/\s+$/,"")};String.prototype.remove=function(t){return this.replaceAll(new RegExp(t,"g"),"")};String.prototype.toAlphanum=function(){return this.replace(/[^a-z0-9]/gi,"")};String.prototype.toAlpha=function(){return this.replace(/[^a-z]/gi,"")};class F{options;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"},logFunction:(r,...n)=>{switch(r){case"ERROR":console.error(...n);break;case"WARN":console.warn(...n);break;case"DEBUG":console.debug(...n);break;case"VERBOSE":console.log(...n);break;default:console.log(...n)}},...t}}write(t,...r){if(this.options.level){let s=this.options.levels.indexOf(this.options.level)??-1,e=this.options.levels.indexOf(t);if(e===-1)throw Error(`Unknown log level: ${t}`);if(e<s)return}let n=[],i=[];if(this.options.timeStamp)i.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)i.push(t);if(i.length>0)n.push(`[${i.join(" ")}]`);n.push(...r),this.options.logFunction(t,...n)}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 u{#t=[];#r=0;options;constructor(t,r){if(t instanceof u)this.options={...t.options,...r},this.#t.push(...t.#t);else if(this.options=r??{},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.#r+=1,this}dedent(){if(this.#r>0)this.#r-=1;return this}getCurrentIndent(){return this.#r}getLines(){return this.toString().split(`
5
+ `)}formatLine(t){let r=(this.options.indentChar??" ").repeat(this.#r*(this.options.indentSize??2));if(this.options.trim)t=t.trim();return(this.options.linePrefix??"")+r+t+(this.options.lineSuffix??"")}write(...t){return this.#t.push(...t.flatMap((r)=>{if(r===void 0)return;if(typeof r==="string")return r;if(r instanceof u)return r.toString();if(typeof r==="function")return r(this);return String(r)}).filter((r)=>r!==void 0)),this}writeLine(...t){return this.write(...t.flatMap((r)=>{return[this.formatLine(r),this.options.lineSeparator??`
6
+ `]}))}writeMap(t,r){return t.forEach((n,i)=>this.write(r(n,i,this))),this}}class L extends u{header(t,r=1){return this.writeLine(`${"#".repeat(r)} ${t}`)}codeBlock(t,r){if(this.write("```"),r!==void 0)this.write(r);if(t!==void 0)this.writeLine("",t).endCodeBlock();return this}endCodeBlock(){return this.writeLine("```")}link(t,r){return this.write(`[${t}](${r})`)}table(t,r){let n=t.map((e,f)=>{let h=e.length;return r.forEach((o)=>{if(o[f])h=Math.max(h,o[f].length)}),h}),i=t.map((e,f)=>e.padEnd(n[f]));this.writeLine("| "+i.join(" | ")+" |");let s=n.map((e)=>"-".repeat(e));return this.writeLine("| "+s.join(" | ")+" |"),r.forEach((e)=>{let f=e.map((h,o)=>h.padEnd(n[o]));this.writeLine("| "+f.join(" | ")+" |")}),this}blockquote(t){let r=t.split(`
7
+ `);this.writeLine("> "+r[0]);for(let n=1;n<r.length;n++)this.writeLine("> "+r[n]);return this}bold(t){return this.write(`**${t}**`)}italic(t){return this.write(`*${t}*`)}item(t){return this.writeLine(`- ${t}`)}items(t){return t.forEach((r)=>this.item(r)),this}orderedList(t,r=1){return t.forEach((n,i)=>this.writeLine(`${(i+r).toString()}. ${n}`)),this}code(t){return this.write(`\`${t}\``)}horizontalRule(){return this.writeLine("---")}image(t,r){return this.writeLine(`![${t}](${r})`)}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((r)=>this.writeLine(`- [${r.checked?"x":" "}] ${r.text}`)),this}#t=0;section(t){return this.#t++,this.header(t,this.#t)}endSection(){if(this.#t>0)this.#t--;return this}setSectionLevel(t){return this.#t=t,this}}export{u as StringBuilder,m as NavigateResult,E as NavigateAction,L as Markdown,F as Logger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/framework",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "homedev framework",
5
5
  "author": "julzor",
6
6
  "license": "ISC",