UNPKG

galho

Version:

galho is js library for create and manipulate dom elements without need compiling, configuration or VirtualDom

79 lines (78 loc) 3.46 kB
export type int = number; export type float = number; export type str = string; export type bool = boolean; export type unk = unknown; export type Obj = Object; export type Primitive = str | number | bool; export type Key = string | number; export interface Dic<T = any> { [key: string]: T; } export interface AnyDic<T = any> { [key: PropertyKey]: T; } /**json array */ export type JsonA = JsonR[]; /**json object */ export type JsonO = { [key: string]: JsonR; }; /**json result */ export type JsonR = str | float | bool | null | JsonA | JsonO; export type falsy = false | 0 | 0n | -0 | "" | undefined | null; export type Pair<V = any, K = str> = [key: K, val: V]; export type Arr<T> = T[] | T; export type Task<T> = T | Promise<T>; /**check if value is instance of type */ export declare const is: <T extends Object>(value: unk, type: abstract new (...args: any) => T) => value is T; /**is string */ export declare const isS: (value: unk) => value is string; /**is function */ export declare const isF: (value: unk) => value is Function; /** is object */ export declare const isO: (value: unk) => value is Dic<any>; /**is number */ export declare const isN: (value: unk) => value is number; /** is boolean */ export declare const isB: (value: unk) => value is boolean; /** is undefined */ export declare const isU: (value: unk) => value is undefined; /** is promise like */ export declare const isP: (value: any) => value is PromiseLike<any>; /** is array */ export declare const isA: <T = any>(value: any) => value is T[]; export declare const wait: (ms?: int) => Promise<unknown>; export declare const assign: { <T>(t: T, ...s: Partial<T>[]): T; } & typeof Object.assign; export declare const clone: <T>(v: T) => T; /**toString, obs null and undefined return an ""(empty string) */ export declare const toStr: (v: unk) => string; /**return def if value is undefined */ export declare const def: <T, D = T>(value: T, def: D) => T | D; /**returns true if value is not false ie.(value===false) t stands for true*/ export declare const t: (value: unknown) => bool; export declare const call: <T>(v: T, cb: (v: T) => any) => T; export declare const sub: <T, K extends keyof T>(arr: T[], key: K) => T[K][]; export declare const distinct: <T>(arr: T[]) => T[]; /**get last item of array */ export declare const z: <T>(a: ArrayLike<T>) => T; export declare const filter: { <T>(arr: Array<T>, filter: (v: T, i: number) => boolean): T[]; /**filter all truethfull values */ <T>(arr: Array<T>): Exclude<T, falsy>[]; }; /**get length of array */ export declare const l: (a: ArrayLike<any>) => number; export declare const arr: <T>(v: T | T[]) => T[]; export declare function iByKey<T, K extends keyof T>(arr: ArrayLike<T>, name: T[K], key: K, i?: number): number; export declare function byKey<T, K extends keyof T>(arr: ArrayLike<T>, name: T[K], key: K, i?: number): T | null; export declare const create: <T extends Object, A extends any[] = any[]>(constructor: new (...a: A) => T, obj: Partial<T>, ...a: A) => T; export declare const json: { (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; }; export declare function set<T, K extends keyof T>(o: T, key: K, val: T[K]): T; export declare const notImp: () => Error; export declare const notF: (key: Key, itemTp?: str, src?: any, srcTp?: str) => Error;