@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
34 lines (33 loc) • 1.71 kB
TypeScript
type Tuple<T> = [T?, T?];
/** Split array into tuples */
export declare const tuple: <T>(arr: T[]) => Tuple<T>[];
/**
* Flat array - unwraps one level of nested arrays
* @deprecated use `Array.prototype.flat` instead
*/
export declare const flat: <T>(arr: (null | T | T[])[]) => T[];
/** Wraps passed object or primitive to array */
export declare const wrap: <T>(arr: undefined | null | T | T[]) => T[];
/** Unwraps empty collection to `undefined` */
export declare function unwrap(value: []): undefined;
/** Unwraps and returns the first element of array-like object */
export declare function unwrap<T>(value: (ArrayLike<T> & {
0: T;
})): T;
/** Unwraps and returns the first element if array-like object */
export declare function unwrap<T>(value: ArrayLike<T>): T | undefined;
/** Unwraps and returns the first element Node of passed NodeList object */
export declare function unwrap<T extends Node>(value: NodeListOf<T>): T | undefined;
/** Unwraps and returns the first element if passed object is array-like, returns an original object otherwise */
export declare function unwrap<T>(value: T): T;
/** Makes array values unique */
export declare const uniq: <T>(arr: T[]) => T[];
/** Create an array filled with the range [0,..,N-1] */
export declare function range(n: number): number[];
/** Create an array filled with values returned by the filler callback */
export declare function range<T>(n: number, filler: (i: number) => T): T[];
/**
* @returns object with a criteria value as a key and an array of original items that belongs to the current criteria value
*/
export declare const groupBy: <T, V extends string | number>(array: T[], group: (item: T) => V) => Record<V, T[]>;
export {};