UNPKG

8.24 kBTypeScriptView Raw
1import { Dictionary, ArrayLike, KeyOfDistributive } from './types';
2import { GradientObject } from '../graphic/Gradient';
3import { ImagePatternObject } from '../graphic/Pattern';
4declare const nativeSlice: (start?: number, end?: number) => any[];
5export declare function guid(): number;
6export declare function logError(...args: any[]): void;
7export declare function clone<T extends any>(source: T): T;
8export declare function merge<T extends Dictionary<any>, S extends Dictionary<any>>(target: T, source: S, overwrite?: boolean): T & S;
9export declare function merge<T extends any, S extends any>(target: T, source: S, overwrite?: boolean): T | S;
10export declare function mergeAll(targetAndSources: any[], overwrite?: boolean): any;
11export declare function extend<T extends Dictionary<any>, S extends Dictionary<any>>(target: T, source: S): T & S;
12export declare function defaults<T extends Dictionary<any>, S extends Dictionary<any>>(target: T, source: S, overlay?: boolean): T & S;
13export declare const createCanvas: () => HTMLCanvasElement;
14export declare function indexOf<T>(array: T[] | readonly T[] | ArrayLike<T>, value: T): number;
15export declare function inherits(clazz: Function, baseClazz: Function): void;
16export declare function mixin<T, S>(target: T | Function, source: S | Function, override?: boolean): void;
17export declare function isArrayLike(data: any): data is ArrayLike<any>;
18export declare function each<I extends Dictionary<any> | any[] | readonly any[] | ArrayLike<any>, Context>(arr: I, cb: (this: Context, value: I extends (infer T)[] | readonly (infer T)[] | ArrayLike<infer T> ? T : I extends Dictionary<any> ? I extends Record<infer K, infer T> ? T : unknown : unknown, index?: I extends any[] | readonly any[] | ArrayLike<any> ? number : keyof I & string, arr?: I) => void, context?: Context): void;
19export declare function map<T, R, Context>(arr: readonly T[], cb: (this: Context, val: T, index?: number, arr?: readonly T[]) => R, context?: Context): R[];
20export declare function reduce<T, S, Context>(arr: readonly T[], cb: (this: Context, previousValue: S, currentValue: T, currentIndex?: number, arr?: readonly T[]) => S, memo?: S, context?: Context): S;
21export declare function filter<T, Context>(arr: readonly T[], cb: (this: Context, value: T, index: number, arr: readonly T[]) => boolean, context?: Context): T[];
22export declare function find<T, Context>(arr: readonly T[], cb: (this: Context, value: T, index?: number, arr?: readonly T[]) => boolean, context?: Context): T;
23export declare function keys<T extends object>(obj: T): (KeyOfDistributive<T> & string)[];
24export declare type Bind1<F, Ctx> = F extends (this: Ctx, ...args: infer A) => infer R ? (...args: A) => R : unknown;
25export declare type Bind2<F, Ctx, T1> = F extends (this: Ctx, a: T1, ...args: infer A) => infer R ? (...args: A) => R : unknown;
26export declare type Bind3<F, Ctx, T1, T2> = F extends (this: Ctx, a: T1, b: T2, ...args: infer A) => infer R ? (...args: A) => R : unknown;
27export declare type Bind4<F, Ctx, T1, T2, T3> = F extends (this: Ctx, a: T1, b: T2, c: T3, ...args: infer A) => infer R ? (...args: A) => R : unknown;
28export declare type Bind5<F, Ctx, T1, T2, T3, T4> = F extends (this: Ctx, a: T1, b: T2, c: T3, d: T4, ...args: infer A) => infer R ? (...args: A) => R : unknown;
29declare type BindFunc<Ctx> = (this: Ctx, ...arg: any[]) => any;
30interface FunctionBind {
31 <F extends BindFunc<Ctx>, Ctx>(func: F, ctx: Ctx): Bind1<F, Ctx>;
32 <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0]>(func: F, ctx: Ctx, a: T1): Bind2<F, Ctx, T1>;
33 <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1]>(func: F, ctx: Ctx, a: T1, b: T2): Bind3<F, Ctx, T1, T2>;
34 <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2]>(func: F, ctx: Ctx, a: T1, b: T2, c: T3): Bind4<F, Ctx, T1, T2, T3>;
35 <F extends BindFunc<Ctx>, Ctx, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2], T4 extends Parameters<F>[3]>(func: F, ctx: Ctx, a: T1, b: T2, c: T3, d: T4): Bind5<F, Ctx, T1, T2, T3, T4>;
36}
37export declare const bind: FunctionBind;
38export declare type Curry1<F, T1> = F extends (a: T1, ...args: infer A) => infer R ? (...args: A) => R : unknown;
39export declare type Curry2<F, T1, T2> = F extends (a: T1, b: T2, ...args: infer A) => infer R ? (...args: A) => R : unknown;
40export declare type Curry3<F, T1, T2, T3> = F extends (a: T1, b: T2, c: T3, ...args: infer A) => infer R ? (...args: A) => R : unknown;
41export declare type Curry4<F, T1, T2, T3, T4> = F extends (a: T1, b: T2, c: T3, d: T4, ...args: infer A) => infer R ? (...args: A) => R : unknown;
42declare type CurryFunc = (...arg: any[]) => any;
43declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0]>(func: F, a: T1): Curry1<F, T1>;
44declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1]>(func: F, a: T1, b: T2): Curry2<F, T1, T2>;
45declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2]>(func: F, a: T1, b: T2, c: T3): Curry3<F, T1, T2, T3>;
46declare function curry<F extends CurryFunc, T1 extends Parameters<F>[0], T2 extends Parameters<F>[1], T3 extends Parameters<F>[2], T4 extends Parameters<F>[3]>(func: F, a: T1, b: T2, c: T3, d: T4): Curry4<F, T1, T2, T3, T4>;
47export { curry };
48export declare function isArray(value: any): value is any[];
49export declare function isFunction(value: any): value is Function;
50export declare function isString(value: any): value is string;
51export declare function isStringSafe(value: any): value is string;
52export declare function isNumber(value: any): value is number;
53export declare function isObject<T = unknown>(value: T): value is (object & T);
54export declare function isBuiltInObject(value: any): boolean;
55export declare function isTypedArray(value: any): boolean;
56export declare function isDom(value: any): value is HTMLElement;
57export declare function isGradientObject(value: any): value is GradientObject;
58export declare function isImagePatternObject(value: any): value is ImagePatternObject;
59export declare function isRegExp(value: unknown): value is RegExp;
60export declare function eqNaN(value: any): boolean;
61export declare function retrieve<T>(...args: T[]): T;
62export declare function retrieve2<T, R>(value0: T, value1: R): T | R;
63export declare function retrieve3<T, R, W>(value0: T, value1: R, value2: W): T | R | W;
64declare type SliceParams = Parameters<typeof nativeSlice>;
65export declare function slice<T>(arr: ArrayLike<T>, ...args: SliceParams): T[];
66export declare function normalizeCssArray(val: number | number[]): number[];
67export declare function assert(condition: any, message?: string): void;
68export declare function trim(str: string): string;
69export declare function setAsPrimitive(obj: any): void;
70export declare function isPrimitive(obj: any): boolean;
71interface MapInterface<T, KEY extends string | number = string | number> {
72 delete(key: KEY): boolean;
73 has(key: KEY): boolean;
74 get(key: KEY): T | undefined;
75 set(key: KEY, value: T): this;
76 keys(): KEY[];
77 forEach(callback: (value: T, key: KEY) => void): void;
78}
79export declare class HashMap<T, KEY extends string | number = string | number> {
80 data: MapInterface<T, KEY>;
81 constructor(obj?: HashMap<T, KEY> | {
82 [key in KEY]?: T;
83 } | KEY[]);
84 hasKey(key: KEY): boolean;
85 get(key: KEY): T;
86 set(key: KEY, value: T): T;
87 each<Context>(cb: (this: Context, value?: T, key?: KEY) => void, context?: Context): void;
88 keys(): KEY[];
89 removeKey(key: KEY): void;
90}
91export declare function createHashMap<T, KEY extends string | number = string | number>(obj?: HashMap<T, KEY> | {
92 [key in KEY]?: T;
93} | KEY[]): HashMap<T, KEY>;
94export declare function concatArray<T, R>(a: ArrayLike<T>, b: ArrayLike<R>): ArrayLike<T | R>;
95export declare function createObject<T>(proto?: object, properties?: T): T;
96export declare function disableUserSelect(dom: HTMLElement): void;
97export declare function hasOwn(own: object, prop: string): boolean;
98export declare function noop(): void;
99export declare const RADIAN_TO_DEGREE: number;