compare-by
Version:
A versatile utility library for sorting arrays of objects by one or multiple keys with customizable sort directions.
12 lines (10 loc) • 411 B
text/typescript
export type OptionalArray<T> = T | Array<T>;
/**
* Returns an array of the input. If the input already is an array, return the input.
* @type {T} The type of the array values.
* @param {T} input The input either as value or as array.
* @returns {Array<T>} The input value as array.
*/
export const arrayify = <T>(input: OptionalArray<T>) => {
return Array.isArray(input) ? input : [input];
};