@alessiofrittoli/web-utils
Version:
Common TypeScript web utilities
51 lines (49 loc) • 1.48 kB
TypeScript
/**
* Removes duplicate values from an array.
*
* @param array The input array.
* @returns The filtered array.
*/
declare const arrayUnique: <T>(array: T[]) => T[];
/**
* Removes duplicate entries from an array referencing an object key.
*
* @param array An array of objects.
* @param property The Object property to refer to.
* @returns The filtered array.
*/
declare const arrayObjectUnique: <T>(array: T[], property: keyof T) => T[];
/**
* Convert a stringified Array to Array object.
*
* @param string The string to convert. ( e.g. `value1, value2` or `value1,value2` )
* @returns The converted string Array.
*/
declare const listToArray: (string: string) => string[];
type ChunkIntoOptions = ({
/**
* Will split the given Array in a way to ensure each chunk length is, whenever possible, equal to the given value.
*
*/
size: number;
count?: never;
} | {
/**
* Will split the given Array in a way to ensure n chunks as the given value.
*
*/
count: number;
size?: never;
});
/**
* Split Array into chunks.
*
* @template T The input `array` type.
*
* @param array The original Array.
* @param options An object defining split criteria. See {@link ChunkIntoOptions} for more info.
*
* @returns An Array of chunks.
*/
declare function chunkInto<T extends unknown[]>(array: T, options: ChunkIntoOptions): T[];
export { type ChunkIntoOptions, arrayObjectUnique, arrayUnique, chunkInto, listToArray };