@alessiofrittoli/web-utils
Version:
Common TypeScript web utilities
69 lines (67 loc) • 2.17 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[];
/**
* Shuffle the elements of an array in place using the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle).
*
* @template T The type of elements in the array.
* @param array The array to shuffle.
*
* @returns The shuffled array.
*/
declare const shuffle: <T>(array: Array<T>) => T[];
/**
* Copy and shuffle the elements of an array in place using the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle).
*
* @template T The type of elements in the array.
* @param array The array to shuffle.
*
* @returns The shuffled array.
*/
declare const shuffleCopy: <T>(array: Array<T>) => T[];
export { type ChunkIntoOptions, arrayObjectUnique, arrayUnique, chunkInto, listToArray, shuffle, shuffleCopy };