@homedev/framework 0.0.3 → 0.0.5

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,16 +1,3 @@
1
- /**
2
- * Constructor for creating async functions dynamically from source code strings.
3
- * Equivalent to the built-in async function constructor.
4
- *
5
- * @example
6
- * ```typescript
7
- * const fn = new AsyncFunction('x', 'y', 'return x + y')
8
- * await fn(2, 3) // 5
9
- * ```
10
- */
11
- declare const AsyncFunction_2: any;
12
- export { AsyncFunction_2 as AsyncFunction }
13
-
14
1
  /**
15
2
  * Guards against undefined and null values.
16
3
  * Throws an error if the value is nullish, otherwise returns the value.
@@ -33,6 +20,29 @@ export { AsyncFunction_2 as AsyncFunction }
33
20
  declare function defined_2<T>(value: T | undefined | null, message?: string): T;
34
21
  export { defined_2 as defined }
35
22
 
23
+ export declare type LogFunction = (className: string, ...args: any[]) => void;
24
+
25
+ export declare class Logger {
26
+ options: LoggerOptions;
27
+ constructor(options?: Partial<LoggerOptions>);
28
+ write(className: string, ...args: any[]): void;
29
+ info(...args: any[]): void;
30
+ error(...args: any[]): void;
31
+ warn(...args: any[]): void;
32
+ debug(...args: any[]): void;
33
+ verbose(...args: any[]): void;
34
+ }
35
+
36
+ export declare interface LoggerOptions {
37
+ level: string;
38
+ showClass: boolean;
39
+ levels: string[];
40
+ timeStamp: boolean;
41
+ timeLocale?: string;
42
+ timeOptions?: Intl.DateTimeFormatOptions;
43
+ logFunction: LogFunction;
44
+ }
45
+
36
46
  /**
37
47
  * @public
38
48
  */
@@ -120,7 +130,6 @@ export declare interface SelectOptions {
120
130
 
121
131
  export { }
122
132
 
123
-
124
133
  /* Global declarations */
125
134
 
126
135
  declare global {
@@ -131,8 +140,6 @@ declare global {
131
140
  var defined: <T>(value: T | undefined | null, msg?: string) => T;
132
141
  }
133
142
 
134
-
135
-
136
143
  declare global {
137
144
  interface Array<T> {
138
145
  mapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
@@ -155,9 +162,6 @@ declare global {
155
162
  }
156
163
  }
157
164
 
158
-
159
-
160
-
161
165
  declare global {
162
166
  interface ObjectConstructor {
163
167
  mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
@@ -170,36 +174,6 @@ declare global {
170
174
  }
171
175
  }
172
176
 
173
- /**
174
- * Guards against undefined and null values.
175
- * Throws an error if the value is nullish, otherwise returns the value.
176
- *
177
- * @param value - The value to check
178
- * @param message - Custom error message (default: 'Value is undefined')
179
- * @returns The value if it is not nullish
180
- * @throws {Error} When value is undefined or null
181
- *
182
- * @example
183
- * ```typescript
184
- * const value = defined(maybeUndefined, 'Required value missing')
185
- * // value is guaranteed to be non-nullish here
186
- *
187
- * defined(0) // 0 (falsy but not nullish)
188
- * defined(false) // false (falsy but not nullish)
189
- * defined(null) // throws Error: Value is undefined
190
- * ```
191
- */
192
- /**
193
- * Re-export AsyncFunction constructor from async module.
194
- * Useful for dynamically creating async functions from source code strings.
195
- *
196
- * @example
197
- * ```typescript
198
- * const fn = new AsyncFunction('x', 'return x * 2')
199
- * await fn(5) // 10
200
- * ```
201
- */
202
-
203
177
  declare global {
204
178
  interface String {
205
179
  capitalize(): string;
@@ -219,95 +193,3 @@ declare global {
219
193
  }
220
194
  }
221
195
 
222
-
223
-
224
- /**
225
- * @public
226
- */
227
- key: string;
228
- value: any;
229
- path: string[];
230
- parent: any;
231
- parents: any[];
232
- }
233
- /**
234
- * @public
235
- */
236
- Explore = 0,
237
- SkipSiblings = 1,
238
- NoExplore = 2,
239
- ReplaceParent = 3,
240
- DeleteParent = 4,
241
- MergeParent = 5,
242
- ReplaceItem = 6,
243
- DeleteItem = 7
244
- }
245
- /**
246
- * @public
247
- */
248
- /**
249
- * @public
250
- */
251
- readonly action: NavigateAction;
252
- by?: any | undefined;
253
- skipSiblings?: boolean | undefined;
254
- reexplore?: boolean | undefined;
255
- constructor(action: NavigateAction, by?: any | undefined, skipSiblings?: boolean | undefined, reexplore?: boolean | undefined);
256
- private static readonly _explore;
257
- private static readonly _noExplore;
258
- private static readonly _skipSiblings;
259
- private static readonly _deleteParent;
260
- static ReplaceParent(by: any, reexplore?: boolean): NavigateResult;
261
- static SkipSiblings(): NavigateResult;
262
- static Explore(): NavigateResult;
263
- static NoExplore(): NavigateResult;
264
- static DeleteParent(): NavigateResult;
265
- static MergeParent(by: any): NavigateResult;
266
- static ReplaceItem(by: any, skipSiblings?: boolean): NavigateResult;
267
- static DeleteItem(skipSiblings?: boolean): NavigateResult;
268
- }
269
-
270
-
271
- /**
272
- * @public
273
- */
274
- /**
275
- * @public
276
- */
277
- conflict?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => any;
278
- mismatch?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => any;
279
- navigate?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => boolean | undefined;
280
- mode?: (key: string, source: any, target: any, sourceContainer: any, targetContainer: any) => MergeMode | void;
281
- }
282
-
283
-
284
- /**
285
- * Options for configuring the select function behavior
286
- * @public
287
- */
288
- /** Value to set at the selected path */
289
- set?: any;
290
- /** Alternative key to use (currently unused) */
291
- key?: string;
292
- /** Path separator character (default: '.') */
293
- separator?: string;
294
- /** Default value to return when path is not found */
295
- defaultValue?: any;
296
- /** If true, returns undefined instead of throwing on missing paths */
297
- optional?: boolean;
298
- }
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- Array.prototype.findOrFail=function(T,n,m){let r=this.find(T,m);if(r===void 0)throw Error(n??"Element not found");return r};Array.flat=function(T){if(Array.isArray(T))return T.flat(2);else return[T]};Array.prototype.forEachAsync=async function(T){for(let n=0;n<this.length;n++)await T(this[n],n,this)};Array.prototype.groupBy=function(T){return this.reduce((n,m)=>{let r=T(m);if(!n[r])n[r]=[];return n[r].push(m),n},{})};Array.prototype.createInstances=function(T,...n){return this.map((m,r)=>new T(...n,m,r))};Array.prototype.mapAsync=async function(T){return Promise.all(this.map(T))};Array.prototype.nonNullMap=function(T){let n=[];for(let m=0;m<this.length;m++){let r=T(this[m],m,this);if(r!=null)n.push(r)}return n};Array.prototype.nonNullMapAsync=async function(T){let n=[];for(let m=0;m<this.length;m++){let r=await T(this[m],m,this);if(r!=null)n.push(r)}return n};Array.prototype.mergeAll=function(T){let n={};for(let m of this.toReversed())Object.merge(m,n,T);return n};Array.prototype.toObject=function(T,n){return Object.fromEntries(this.map((m)=>{let r=T(m),f=n?n(m):m;return[r,f]}))};Array.prototype.toObjectWithKey=function(T){return Object.fromEntries(this.map((n)=>[String(n[T]),n]))};Array.prototype.selectFor=function(T,n,m,r){let f=this.find(T,r);if(f===void 0)throw Error(m??"Element not found");return n(f)};Array.prototype.sortBy=function(T,n=!0){return this.slice().sort((m,r)=>{let f=T(m),b=T(r);if(f<b)return n?-1:1;if(f>b)return n?1:-1;return 0})};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(T){let n=new Set;return this.filter((m)=>{let r=T(m);if(n.has(r))return!1;else return n.add(r),!0})};var y;((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"})(y||={});class F{action;by;skipSiblings;reexplore;constructor(T,n,m,r){this.action=T;this.by=n;this.skipSiblings=m;this.reexplore=r}static _explore=new F(0);static _noExplore=new F(2);static _skipSiblings=new F(1);static _deleteParent=new F(4);static ReplaceParent(T,n){return new F(3,T,void 0,n)}static SkipSiblings(){return F._skipSiblings}static Explore(){return F._explore}static NoExplore(){return F._noExplore}static DeleteParent(){return F._deleteParent}static MergeParent(T){return new F(5,T)}static ReplaceItem(T,n){return new F(6,T,n)}static DeleteItem(T){return new F(7,void 0,T)}}Object.navigate=async(T,n)=>{let m=new WeakSet,r=[],f=[],b=async(o,x,E)=>{let O=o===null,A=O?F.Explore():await n({key:o,value:x,path:r,parent:E,parents:f});if(x&&typeof x==="object"&&A.action===0){if(m.has(x))return A;if(m.add(x),!O)r.push(o),f.push(E);let w=x;while(await d(w,o,E))w=E[o];if(!O)f.pop(),r.pop()}return A},d=async(o,x,E)=>{let O=Object.keys(o),U=O.length;for(let A=0;A<U;A++){let B=O[A],C=o[B],w=await b(B,C,o),K=w.action;if(K===0||K===2)continue;if(K===6){if(o[B]=w.by,w.skipSiblings)return;continue}if(K===7){if(delete o[B],w.skipSiblings)return;continue}if(K===1)return;if(K===3){if(x===null)throw Error("Cannot replace root object");if(E[x]=w.by,w.reexplore)return!0;return}if(K===4){if(x===null)throw Error("Cannot delete root object");delete E[x];return}if(K===5)delete o[B],Object.assign(o,w.by)}};await b(null,T,null)};Object.find=async function(T,n){let m=[];return await Object.navigate(T,(r)=>{if(n([...r.path,r.key].join("."),r.value))m.push(r.value);return F.Explore()}),m};Object.merge=(T,n,m)=>{for(let r of Object.keys(n)){if(T[r]===void 0)continue;let f=n[r],b=T[r];if(typeof b!==typeof f||Array.isArray(b)!==Array.isArray(f)){let o=m?.mismatch?.(r,b,f,T,n);if(o!==void 0){n[r]=o;continue}throw Error(`Type mismatch: ${r}`)}let d=m?.mode?.(r,b,f,T,n)??n[".merge"]??"merge";switch(d){case"source":n[r]=b;continue;case"target":continue;case"skip":delete n[r],delete T[r];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${d}`)}if(typeof b==="object")if(Array.isArray(b))f.push(...b);else{if(m?.navigate?.(r,b,f,T,n)===!1)continue;Object.merge(b,f,m)}else{if(b===f)continue;let o=m?.conflict?.(r,b,f,T,n);n[r]=o===void 0?f:o}}for(let r of Object.keys(T))if(n[r]===void 0)n[r]=T[r]};var I=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,X=/^([^[\]]*)\[([^\]]*)]$/,P=(T,n,m,r)=>{if(T.startsWith("{")&&T.endsWith("}")){let f=T.substring(1,T.length-1);return Object.select(n,f,m)?.toString()}return r?T:void 0},j=(T,n,m,r)=>{let f=P(n,m,r);if(f)return Object.select(T,f,r);let b=I.exec(n);if(b){let[,o,x,E]=b,O=P(o.trim(),m,r,!0),U=P(E.trim(),m,r,!0);if(Array.isArray(T)&&(x==="="||x==="==")&&O)return T.find((A)=>A?.[O]==U)}let d=X.exec(n);if(d){let[,o,x]=d;return T?.[o]?.[x]}return T?.[n]};Object.select=(T,n,m)=>{let r=void 0,f=void 0,b=n??"",d=(U)=>{if(!U)return[U,!1];return U.endsWith("?")?[U.substring(0,U.length-1),!0]:[U,!1]},o=(U,A)=>{let[B,C]=d(A.pop());if(!B){if(m?.set!==void 0&&f!==void 0&&r!==void 0)r[f]=m.set;return U}let w=j(U,B,T,m);if(w===void 0){if(C||m?.optional||m?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${B}" in "${b}"`)}return r=U,f=B,o(w,A)},x=b.splitNested(m?.separator??".","{","}"),E=void 0;if(x.length>0&&x[x.length-1].startsWith("?="))E=x.pop()?.substring(2);x.reverse();let O=o(T,x);if(O===void 0)return E??m?.defaultValue;return O};Object.deepClone=function(T){if(typeof structuredClone<"u")try{return structuredClone(T)}catch{}return JSON.parse(JSON.stringify(T))};Object.toList=function(T,n){return Object.entries(T).map(([m,r])=>({[n]:m,...r}))};Object.mapEntries=function(T,n){let r=Object.entries(T).map(([f,b])=>n(f,b));return Object.fromEntries(r)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;global.defined=(T,n="Value is undefined")=>{if(T===void 0||T===null)throw Error(n);return T};String.prototype.tokenize=function(T,n=/\${([^}]+)}/g){return this.replace(n,(m,r)=>{let f=T[r];if(f===null||f===void 0)return"";if(typeof f==="string")return f;if(typeof f==="number"||typeof f==="boolean")return String(f);return String(f)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(T,n)=>n.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capitalize=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(T,n)=>n.toUpperCase())};String.prototype.toCamel=function(){return this.toPascal().replace(/((?:[ ]+\w)|^\w)/g,(T,n)=>n.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 n=[],m=this.length,r=T.length,f=0,b=(d)=>{if(d+r>m)return!1;for(let o=0;o<r;o++)if(this[d+o]!==T[o])return!1;return!0};while(f<m){while(f<m&&this[f]===" ")f++;if(f>=m)break;let d="",o=this[f]==='"'||this[f]==="'";if(o){let x=this[f++];while(f<m&&this[f]!==x)d+=this[f++];if(f<m)f++}else{while(f<m&&!b(f)){let x=this[f];if(x==='"'||x==="'"){d+=x,f++;while(f<m&&this[f]!==x)d+=this[f++];if(f<m)d+=this[f++]}else d+=this[f++]}d=d.trim()}if(d)n.push({value:d,quoted:o});if(b(f))f+=r}return n};String.prototype.splitNested=function(T,n,m){let r=0,f="",b=[];for(let d of this){if(f+=d,d===n)r++;if(d===m)r--;if(r===0&&d===T)b.push(f.slice(0,-1)),f=""}if(f)b.push(f);return b};String.prototype.padBlock=function(T,n=`
2
- `,m=" "){let r=m.repeat(T);return this.split(n).map((f)=>r+f).join(n)};String.prototype.stripIndent=function(){let T=this.split(/\r?\n/),n=T.filter((r)=>r.trim().length>0).map((r)=>/^[ \t]*/.exec(r)?.[0].length??0),m=n.length>0?Math.min(...n):0;if(m===0)return this;return T.map((r)=>r.slice(m)).join(`
3
- `)};var W=Object.getPrototypeOf(async function(){}).constructor;function i(T,n="Value is undefined"){if(T===void 0||T===null)throw Error(n);return T}export{i as defined,F as NavigateResult,y as NavigateAction,W as AsyncFunction};
1
+ Array.prototype.findOrFail=function(n,r,T){let o=this.find(n,T);if(o===void 0)throw Error(r??"Element not found");return o};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 o=n(T);if(!r[o])r[o]=[];return r[o].push(T),r},{})};Array.prototype.createInstances=function(n,...r){return this.map((T,o)=>new n(...r,T,o))};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 o=n(this[T],T,this);if(o!=null)r.push(o)}return r};Array.prototype.nonNullMapAsync=async function(n){let r=[];for(let T=0;T<this.length;T++){let o=await n(this[T],T,this);if(o!=null)r.push(o)}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 o=n(T),f=r?r(T):T;return[o,f]}))};Array.prototype.toObjectWithKey=function(n){return Object.fromEntries(this.map((r)=>[String(r[n]),r]))};Array.prototype.selectFor=function(n,r,T,o){let f=this.find(n,o);if(f===void 0)throw Error(T??"Element not found");return r(f)};Array.prototype.sortBy=function(n,r=!0){return this.slice().sort((T,o)=>{let f=n(T),m=n(o);if(f<m)return r?-1:1;if(f>m)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 o=n(T);if(r.has(o))return!1;else return r.add(o),!0})};var e;((s)=>{s[s.Explore=0]="Explore";s[s.SkipSiblings=1]="SkipSiblings";s[s.NoExplore=2]="NoExplore";s[s.ReplaceParent=3]="ReplaceParent";s[s.DeleteParent=4]="DeleteParent";s[s.MergeParent=5]="MergeParent";s[s.ReplaceItem=6]="ReplaceItem";s[s.DeleteItem=7]="DeleteItem"})(e||={});class x{action;by;skipSiblings;reexplore;constructor(n,r,T,o){this.action=n;this.by=r;this.skipSiblings=T;this.reexplore=o}static _explore=new x(0);static _noExplore=new x(2);static _skipSiblings=new x(1);static _deleteParent=new x(4);static ReplaceParent(n,r){return new x(3,n,void 0,r)}static SkipSiblings(){return x._skipSiblings}static Explore(){return x._explore}static NoExplore(){return x._noExplore}static DeleteParent(){return x._deleteParent}static MergeParent(n){return new x(5,n)}static ReplaceItem(n,r){return new x(6,n,r)}static DeleteItem(n){return new x(7,void 0,n)}}Object.navigate=async(n,r)=>{let T=new WeakSet,o=[],f=[],m=async(d,s,h)=>{let w=d===null,E=w?x.Explore():await r({key:d,value:s,path:o,parent:h,parents:f});if(s&&typeof s==="object"&&E.action===0){if(T.has(s))return E;if(T.add(s),!w)o.push(d),f.push(h);let b=s;while(await t(b,d,h))b=h[d];if(!w)f.pop(),o.pop()}return E},t=async(d,s,h)=>{let w=Object.keys(d),i=w.length;for(let E=0;E<i;E++){let O=w[E],U=d[O],b=await m(O,U,d),F=b.action;if(F===0||F===2)continue;if(F===6){if(d[O]=b.by,b.skipSiblings)return;continue}if(F===7){if(delete d[O],b.skipSiblings)return;continue}if(F===1)return;if(F===3){if(s===null)throw Error("Cannot replace root object");if(h[s]=b.by,b.reexplore)return!0;return}if(F===4){if(s===null)throw Error("Cannot delete root object");delete h[s];return}if(F===5)delete d[O],Object.assign(d,b.by)}};await m(null,n,null)};Object.find=async function(n,r){let T=[];return await Object.navigate(n,(o)=>{if(r([...o.path,o.key].join("."),o.value))T.push(o.value);return x.Explore()}),T};Object.merge=(n,r,T)=>{for(let o of Object.keys(r)){if(n[o]===void 0)continue;let f=r[o],m=n[o];if(typeof m!==typeof f||Array.isArray(m)!==Array.isArray(f)){let d=T?.mismatch?.(o,m,f,n,r);if(d!==void 0){r[o]=d;continue}throw Error(`Type mismatch: ${o}`)}let t=T?.mode?.(o,m,f,n,r)??r[".merge"]??"merge";switch(t){case"source":r[o]=m;continue;case"target":continue;case"skip":delete r[o],delete n[o];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${t}`)}if(typeof m==="object")if(Array.isArray(m))f.push(...m);else{if(T?.navigate?.(o,m,f,n,r)===!1)continue;Object.merge(m,f,T)}else{if(m===f)continue;let d=T?.conflict?.(o,m,f,n,r);r[o]=d===void 0?f:d}}for(let o of Object.keys(n))if(r[o]===void 0)r[o]=n[o]};var c=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,g=/^([^[\]]*)\[([^\]]*)]$/,p=(n,r,T,o)=>{if(n.startsWith("{")&&n.endsWith("}")){let f=n.substring(1,n.length-1);return Object.select(r,f,T)?.toString()}return o?n:void 0},y=(n,r,T,o)=>{let f=p(r,T,o);if(f)return Object.select(n,f,o);let m=c.exec(r);if(m){let[,d,s,h]=m,w=p(d.trim(),T,o,!0),i=p(h.trim(),T,o,!0);if(Array.isArray(n)&&(s==="="||s==="==")&&w)return n.find((E)=>E?.[w]==i)}let t=g.exec(r);if(t){let[,d,s]=t;return n?.[d]?.[s]}return n?.[r]};Object.select=(n,r,T)=>{let o=void 0,f=void 0,m=r??"",t=(i)=>{if(!i)return[i,!1];return i.endsWith("?")?[i.substring(0,i.length-1),!0]:[i,!1]},d=(i,E)=>{let[O,U]=t(E.pop());if(!O){if(T?.set!==void 0&&f!==void 0&&o!==void 0)o[f]=T.set;return i}let b=y(i,O,n,T);if(b===void 0){if(U||T?.optional||T?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${O}" in "${m}"`)}return o=i,f=O,d(b,E)},s=m.splitNested(T?.separator??".","{","}"),h=void 0;if(s.length>0&&s[s.length-1].startsWith("?="))h=s.pop()?.substring(2);s.reverse();let w=d(n,s);if(w===void 0)return h??T?.defaultValue;return w};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,o])=>({[r]:T,...o}))};Object.mapEntries=function(n,r){let o=Object.entries(n).map(([f,m])=>r(f,m));return Object.fromEntries(o)};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,o)=>{let f=n[o];if(f===null||f===void 0)return"";if(typeof f==="string")return f;if(typeof f==="number"||typeof f==="boolean")return String(f);return String(f)})};String.prototype.toPascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(n,r)=>r.toUpperCase()).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,o=n.length,f=0,m=(t)=>{if(t+o>T)return!1;for(let d=0;d<o;d++)if(this[t+d]!==n[d])return!1;return!0};while(f<T){while(f<T&&this[f]===" ")f++;if(f>=T)break;let t="",d=this[f]==='"'||this[f]==="'";if(d){let s=this[f++];while(f<T&&this[f]!==s)t+=this[f++];if(f<T)f++}else{while(f<T&&!m(f)){let s=this[f];if(s==='"'||s==="'"){t+=s,f++;while(f<T&&this[f]!==s)t+=this[f++];if(f<T)t+=this[f++]}else t+=this[f++]}t=t.trim()}if(t)r.push({value:t,quoted:d});if(m(f))f+=o}return r};String.prototype.splitNested=function(n,r,T){let o=0,f="",m=[];for(let t of this){if(f+=t,t===r)o++;if(t===T)o--;if(o===0&&t===n)m.push(f.slice(0,-1)),f=""}if(f)m.push(f);return m};String.prototype.padBlock=function(n,r=`
2
+ `,T=" "){let o=T.repeat(n);return this.split(r).map((f)=>o+f).join(r)};String.prototype.stripIndent=function(){let n=this.split(/\r?\n/),r=n.filter((o)=>o.trim().length>0).map((o)=>/^[ \t]*/.exec(o)?.[0].length??0),T=r.length>0?Math.min(...r):0;if(T===0)return this;return n.map((o)=>o.slice(T)).join(`
3
+ `)};function V(n,r="Value is undefined"){if(n===void 0||n===null)throw Error(r);return n}class B{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 f=this.options.levels.indexOf(this.options.level)??-1,m=this.options.levels.indexOf(n);if(m===-1)throw Error(`Unknown log level: ${n}`);if(m<f)return}let T=[],o=[];if(this.options.timeStamp)o.push(new Date().toLocaleString(this.options.timeLocale,this.options.timeOptions));if(this.options.showClass)o.push(n);if(o.length>0)T.push(`[${o.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)}}export{V as defined,x as NavigateResult,e as NavigateAction,B as Logger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/framework",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "homedev framework",
5
5
  "author": "julzor",
6
6
  "license": "ISC",