UNPKG

@yantrix/utils

Version:

Shared code for Yantrix framework

48 lines (42 loc) 2.31 kB
declare function unifyObjectKey<KeyType = number>(key: string | number): KeyType; type TLengthArray<T, N extends number, R extends T[] = []> = number extends N ? T[] : R['length'] extends N ? R : TLengthArray<T, N, [T, ...R]>; type TStaticMethods = { id: string; actions: Record<string, string>; states: Record<string, string>; getState: (state: any) => number; hasState: (instance: any, state: any) => boolean; getAction: (action: any) => number; createAction: (action: any, payload: any) => { action: number; payload: any; }; }; type TClassConstructor<C> = { new (...args: any[]): C; }; type TKeys<T> = keyof T; type TNullable<T> = T | null; declare function randomString(length?: number): string; declare function randomInteger(min?: number, max?: number): number; declare const randomDecimal: (min?: number, max?: number) => number; declare function randomValueFunction(): ((min?: number, max?: number) => number) | typeof randomString; declare function randomValue(): number | string; declare function randomArray(valueType: () => any, amount?: number): any[]; declare function sampleRange(min?: number, max?: number): number; declare function pickFromArray<T>(arr: T[], n?: number): T[]; declare function popFromArray<T>(arr: T[], n?: number): T[]; declare function sampleArray<T = number, N extends number = number>(item: null | ((index?: number) => T) | T, n: N): TLengthArray<T, N>; /** * Generate a random alphanumeric ID of a given length. * @param {number} length * @return {string} */ declare function uniqId(length?: number): string; declare function microtime(): number; declare const isNumber: (t: any) => t is number; declare const isPositiveNumber: (t: any) => t is number; declare const isPositiveInteger: (t: any) => t is number; declare const isInteger: (t: any) => t is number; declare const isStaticMethodsAutomata: (Automata: any) => Automata is TStaticMethods; export { type TClassConstructor, type TKeys, type TLengthArray, type TNullable, type TStaticMethods, isInteger, isNumber, isPositiveInteger, isPositiveNumber, isStaticMethodsAutomata, microtime, pickFromArray, popFromArray, randomArray, randomDecimal, randomInteger, randomString, randomValue, randomValueFunction, sampleArray, sampleRange, unifyObjectKey, uniqId };