@homedev/framework 0.0.1 → 0.0.2

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.js CHANGED
@@ -1 +1,3 @@
1
- Array.prototype.mapAsync=async function(e){let r=[];for(let t=0;t<this.length;t++)r.push(await e(this[t],t,this));return r};Array.prototype.nonNullMap=function(e){let r=[];for(let t=0;t<this.length;t++){let n=e(this[t],t,this);if(n!=null)r.push(n)}return r};Array.prototype.nonNullMapAsync=async function(e){let r=[];for(let t=0;t<this.length;t++){let n=await e(this[t],t,this);if(n!=null)r.push(n)}return r};Array.prototype.sortBy=function(e,r=!0){return this.slice().sort((t,n)=>{let o=e(t),s=e(n);if(o<s)return r?-1:1;if(o>s)return r?1:-1;return 0})};Array.prototype.forEachAsync=async function(e){for(let r=0;r<this.length;r++)await e(this[r],r,this)};Array.prototype.unique=function(){return Array.from(new Set(this))};Array.prototype.uniqueBy=function(e){let r=new Set;return this.filter((t)=>{let n=e(t);if(r.has(n))return!1;else return r.add(n),!0})};Array.prototype.groupBy=function(e){return this.reduce((r,t)=>{let n=e(t);if(!r[n])r[n]=[];return r[n].push(t),r},{})};Array.prototype.toObject=function(e,r){return Object.fromEntries(this.map((t)=>{let n=e(t),o=r?r(t):t;return[n,o]}))};Array.prototype.toObjectWithKey=function(e){return Object.fromEntries(this.map((r)=>[String(r[e]),r]))};Array.prototype.findOrFail=function(e,r,t){let n=this.find(e,t);if(n===void 0)throw Error(r??"Element not found");return n};Array.prototype.selectFor=function(e,r,t,n){let o=this.find(e,n);if(o===void 0)throw Error(t??"Element not found");return r(o)};Array.flat=function(e){if(Array.isArray(e))return e.flat(2);else return[e]};Array.prototype.createInstances=function(e,...r){return this.map((t,n)=>new e(...r,t,n))};Object.mapEntries=function(e,r){let n=Object.entries(e).map(([o,s])=>r(o,s));return Object.fromEntries(n)};Object.toList=function(e,r){return Object.entries(e).map(([t,n])=>({[r]:t,...n}))};Object.deepClone=function(e){if(typeof structuredClone<"u")try{return structuredClone(e)}catch{}return JSON.parse(JSON.stringify(e))};Object.find=function(e,r){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let n=e[t];if(n!==void 0&&r(n,t))return[t,n]}return};Object.findAll=function(e,r){let t=[];for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)){let o=e[n];if(o!==void 0&&r(o,n))t.push([n,o])}return t};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;String.prototype.pascal=function(){return this.replace(/((?:[_ ]+)\w|^\w)/g,(e,r)=>r.toUpperCase()).replace(/[_ ]/g,"")};String.prototype.capital=function(){return this.replace(/((?:[ ]+)\w|^\w)/g,(e,r)=>r.toUpperCase())};String.prototype.camel=function(){return this.pascal().replace(/((?:[ ]+\w)|^\w)/g,(e,r)=>r.toLowerCase())};String.prototype.snake=function(e){return this.replace(/([a-z])([A-Z])/g,`$1${e}$2`).replace(/\s+/g,e)};String.prototype.kebab=function(){return this.snake("-")};var c=Object.getPrototypeOf(async function(){}).constructor;export{c as AsyncFunction};
1
+ Array.prototype.findOrFail=function(n,r,o){let T=this.find(n,o);if(T===void 0)throw Error(r??"Element not found");return T};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,o)=>{let T=n(o);if(!r[T])r[T]=[];return r[T].push(o),r},{})};Array.prototype.createInstances=function(n,...r){return this.map((o,T)=>new n(...r,o,T))};Array.prototype.mapAsync=async function(n){return Promise.all(this.map(n))};Array.prototype.nonNullMap=function(n){let r=[];for(let o=0;o<this.length;o++){let T=n(this[o],o,this);if(T!=null)r.push(T)}return r};Array.prototype.nonNullMapAsync=async function(n){let r=[];for(let o=0;o<this.length;o++){let T=await n(this[o],o,this);if(T!=null)r.push(T)}return r};Array.prototype.mergeAll=function(n){let r={};for(let o of this.toReversed())Object.merge(o,r,n);return r};Array.prototype.toObject=function(n,r){return Object.fromEntries(this.map((o)=>{let T=n(o),t=r?r(o):o;return[T,t]}))};Array.prototype.toObjectWithKey=function(n){return Object.fromEntries(this.map((r)=>[String(r[n]),r]))};Array.prototype.selectFor=function(n,r,o,T){let t=this.find(n,T);if(t===void 0)throw Error(o??"Element not found");return r(t)};Array.prototype.sortBy=function(n,r=!0){return this.slice().sort((o,T)=>{let t=n(o),m=n(T);if(t<m)return r?-1:1;if(t>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((o)=>{let T=n(o);if(r.has(T))return!1;else return r.add(T),!0})};var K;((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"})(K||={});class d{action;by;skipSiblings;reexplore;constructor(n,r,o,T){this.action=n;this.by=r;this.skipSiblings=o;this.reexplore=T}static _explore=new d(0);static _noExplore=new d(2);static _skipSiblings=new d(1);static _deleteParent=new d(4);static ReplaceParent(n,r){return new d(3,n,void 0,r)}static SkipSiblings(){return d._skipSiblings}static Explore(){return d._explore}static NoExplore(){return d._noExplore}static DeleteParent(){return d._deleteParent}static MergeParent(n){return new d(5,n)}static ReplaceItem(n,r){return new d(6,n,r)}static DeleteItem(n){return new d(7,void 0,n)}}Object.navigate=async(n,r)=>{let o=new WeakSet,T=[],t=[],m=async(s,f,b)=>{let p=s===null,y=p?d.Explore():await r({key:s,value:f,path:T,parent:b,parents:t});if(f&&typeof f==="object"&&y.action===0){if(o.has(f))return y;if(o.add(f),!p)T.push(s),t.push(b);let c=f;while(await i(c,s,b))c=b[s];if(!p)t.pop(),T.pop()}return y},i=async(s,f,b)=>{let p=Object.keys(s),x=p.length;for(let y=0;y<x;y++){let h=p[y],O=s[h],c=await m(h,O,s),U=c.action;if(U===0||U===2)continue;if(U===6){if(s[h]=c.by,c.skipSiblings)return;continue}if(U===7){if(delete s[h],c.skipSiblings)return;continue}if(U===1)return;if(U===3){if(f===null)throw Error("Cannot replace root object");if(b[f]=c.by,c.reexplore)return!0;return}if(U===4){if(f===null)throw Error("Cannot delete root object");delete b[f];return}if(U===5)delete s[h],Object.assign(s,c.by)}};await m(null,n,null)};Object.find=async function(n,r){let o=[];return await Object.navigate(n,(T)=>{if(r([...T.path,T.key].join("."),T.value))o.push(T.value);return d.Explore()}),o};Object.merge=(n,r,o)=>{for(let T of Object.keys(r)){if(n[T]===void 0)continue;let t=r[T],m=n[T];if(typeof m!==typeof t||Array.isArray(m)!==Array.isArray(t)){let s=o?.mismatch?.(T,m,t,n,r);if(s!==void 0){r[T]=s;continue}throw Error(`Type mismatch: ${T}`)}let i=o?.mode?.(T,m,t,n,r)??r[".merge"]??"merge";switch(i){case"source":r[T]=m;continue;case"target":continue;case"skip":delete r[T],delete n[T];continue;case"merge":break;default:throw Error(`Unknown merge mode: ${i}`)}if(typeof m==="object")if(Array.isArray(m))t.push(...m);else{if(o?.navigate?.(T,m,t,n,r)===!1)continue;Object.merge(m,t,o)}else{if(m===t)continue;let s=o?.conflict?.(T,m,t,n,r);r[T]=s===void 0?t:s}}for(let T of Object.keys(n))if(r[T]===void 0)r[T]=n[T]};var A=/^\[([^=\]]*)([=]*)([^\]]*)\]$/,P=/^([^[\]]*)\[([^\]]*)]$/,w=(n,r,o,T)=>{if(n.startsWith("{")&&n.endsWith("}")){let t=n.substring(1,n.length-1);return Object.select(r,t,o)?.toString()}return T?n:void 0},B=(n,r,o,T)=>{let t=w(r,o,T);if(t)return Object.select(n,t,T);let m=A.exec(r);if(m){let[,s,f,b]=m,p=w(s.trim(),o,T,!0),x=w(b.trim(),o,T,!0);if(Array.isArray(n)&&(f==="="||f==="==")&&p)return n.find((y)=>y?.[p]==x)}let i=P.exec(r);if(i){let[,s,f]=i;return n?.[s]?.[f]}return n?.[r]};Object.select=(n,r,o)=>{let T=void 0,t=void 0,m=r??"",i=(x)=>{if(!x)return[x,!1];return x.endsWith("?")?[x.substring(0,x.length-1),!0]:[x,!1]},s=(x,y)=>{let[h,O]=i(y.pop());if(!h){if(o?.set!==void 0&&t!==void 0&&T!==void 0)T[t]=o.set;return x}let c=B(x,h,n,o);if(c===void 0){if(O||o?.optional||o?.defaultValue!==void 0)return;throw Error(`Unknown path element: "${h}" in "${m}"`)}return T=x,t=h,s(c,y)},f=m.splitNested(o?.separator??".","{","}"),b=void 0;if(f.length>0&&f[f.length-1].startsWith("?="))b=f.pop()?.substring(2);f.reverse();let p=s(n,f);if(p===void 0)return b??o?.defaultValue;return p};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(([o,T])=>({[r]:o,...T}))};Object.mapEntries=function(n,r){let T=Object.entries(n).map(([t,m])=>r(t,m));return Object.fromEntries(T)};global.AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;String.prototype.tokenize=function(n,r=/\${([^}]+)}/g){return this.replace(r,(o,T)=>{let t=n[T];if(t===null||t===void 0)return"";if(typeof t==="string")return t;if(typeof t==="number"||typeof t==="boolean")return String(t);return String(t)})};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.splitWithQuotes=function(n=","){let r=[],o=this.length,T=n.length,t=0,m=(i)=>{if(i+T>o)return!1;for(let s=0;s<T;s++)if(this[i+s]!==n[s])return!1;return!0};while(t<o){while(t<o&&this[t]===" ")t++;if(t>=o)break;let i="",s=this[t]==='"'||this[t]==="'";if(s){let f=this[t++];while(t<o&&this[t]!==f)i+=this[t++];if(t<o)t++}else{while(t<o&&!m(t)){let f=this[t];if(f==='"'||f==="'"){i+=f,t++;while(t<o&&this[t]!==f)i+=this[t++];if(t<o)i+=this[t++]}else i+=this[t++]}i=i.trim()}if(i)r.push({value:i,quoted:s});if(m(t))t+=T}return r};String.prototype.splitNested=function(n,r,o){let T=0,t="",m=[];for(let i of this){if(t+=i,i===r)T++;if(i===o)T--;if(T===0&&i===n)m.push(t.slice(0,-1)),t=""}if(t)m.push(t);return m};String.prototype.padBlock=function(n,r=`
2
+ `,o=" "){let T=o.repeat(n);return this.split(r).map((t)=>T+t).join(r)};String.prototype.stripIndent=function(){let n=this.split(/\r?\n/),r=n.filter((T)=>T.trim().length>0).map((T)=>/^[ \t]*/.exec(T)?.[0].length??0),o=r.length>0?Math.min(...r):0;if(o===0)return this;return n.map((T)=>T.slice(o)).join(`
3
+ `)};var V=(n,r="Value is undefined")=>{if(n===void 0||n===null)throw Error(r);return n};var Tn=Object.getPrototypeOf(async function(){}).constructor;export{V as defined,d as NavigateResult,K as NavigateAction,Tn as AsyncFunction};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homedev/framework",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "homedev framework",
5
5
  "author": "julzor",
6
6
  "license": "ISC",
package/dist/index.d.ts DELETED
@@ -1,56 +0,0 @@
1
- declare const AsyncFunction_2: any;
2
- export { AsyncFunction_2 as AsyncFunction }
3
-
4
- export { }
5
-
6
-
7
- /* Global declarations */
8
-
9
- declare global {
10
- type Constructor<T = any> = new (...args: any[]) => T;
11
- type MaybePromise<T> = T | Promise<T>;
12
- type AsyncFunction<T = any> = (...args: any[]) => Promise<T>;
13
- var AsyncFunction: typeof Function;
14
- }
15
-
16
-
17
- declare global {
18
- interface Array<T> {
19
- mapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]>;
20
- forEachAsync(callback: (value: T, index: number, array: T[]) => Promise<void>): Promise<void>;
21
- sortBy<K extends keyof T>(selector: (item: T) => T[K], ascending?: boolean): T[];
22
- unique(): T[];
23
- uniqueBy<K extends keyof T>(selector: (item: T) => T[K]): T[];
24
- groupBy<K extends keyof T>(selector: (item: T) => T[K]): Record<T[K] & (string | number | symbol), T[]>;
25
- toObject<K extends keyof T, V>(keySelector: (item: T) => T[K], valueSelector?: (item: T) => V): Record<T[K] & (string | number | symbol), V>;
26
- toObjectWithKey<K extends keyof T>(key: K): Record<string, T>;
27
- nonNullMap<U>(callback: (value: T, index: number, array: T[]) => U | null | undefined): U[];
28
- nonNullMapAsync<U>(callback: (value: T, index: number, array: T[]) => Promise<U | null | undefined>): Promise<U[]>;
29
- findOrFail(predicate: (value: T, index: number, array: T[]) => boolean, message?: string, thisArg?: any): T;
30
- selectFor<K>(predicate: (value: T, index: number, array: T[]) => boolean, selector: (value: T) => K, message?: string, thisArg?: any): K;
31
- createInstances<TTarget>(targetConstructor: new (...args: any[]) => TTarget, ...args: any[]): TTarget[];
32
- }
33
- interface ArrayConstructor {
34
- flat<T>(v: T | T[] | T[][]): T[];
35
- }
36
- }
37
-
38
- declare global {
39
- interface String {
40
- pascal(): string;
41
- capital(): string;
42
- camel(): string;
43
- snake(separator: string): string;
44
- kebab(): string;
45
- }
46
- }
47
-
48
- declare global {
49
- interface ObjectConstructor {
50
- mapEntries<T extends object, U>(obj: T, callback: (key: keyof T, value: T[keyof T]) => [string | number | symbol, U]): Record<string | number | symbol, U>;
51
- toList<T extends object, U extends object, X extends string>(obj: T, key: X): (Record<X, string> & U)[];
52
- deepClone<T extends object>(obj: T): T;
53
- find<T extends object, K extends keyof T>(obj: Record<string, T>, predicate: (value: T, key: string) => boolean): [K, T] | undefined;
54
- findAll<T extends object, K extends keyof T>(obj: Record<string, T>, predicate: (value: T, key: string) => boolean): [K, T][];
55
- }
56
- }