UNPKG

@thi.ng/arrays

Version:

Array / Arraylike utilities

21 lines 606 B
/** * Helper function to avoid unnecessary copying if `x` is already an * array. * * @remarks * First checks if `x` is an array and if so returns it. Else attempts * to obtain an iterator from `x` and if successful collects it as array * and returns it. Throws error if `x` isn't iterable. * * @param x - */ export declare const ensureArray: <T = any>(x: any) => T[]; /** * Similar to {@link ensureArray}, but for `ArrayLike` types. * * {@link ensureArray} * * @param x - */ export declare const ensureArrayLike: <T = any>(x: any) => ArrayLike<T>; //# sourceMappingURL=ensure-array.d.ts.map