@homedev/framework 0.0.1

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.
@@ -0,0 +1,56 @@
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
+ }
package/dist/index.js ADDED
@@ -0,0 +1 @@
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};
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@homedev/framework",
3
+ "version": "0.0.1",
4
+ "description": "homedev framework",
5
+ "author": "julzor",
6
+ "license": "ISC",
7
+ "main": "dist/index.js",
8
+ "type": "module",
9
+ "typings": "dist/index.d.ts"
10
+ }