typedash
Version:
modern, type-safe collection of utility functions
85 lines (84 loc) • 2.92 kB
TypeScript
import { t as Many } from "./Many-CC3hL8UU.js";
import { t as Maybe } from "./Maybe-pvX1mStM.js";
//#region src/functions/castArray/castArray.d.ts
/**
* Casts the input value to an array if it is not already an array.
* @param value The input value to cast to an array.
* @returns An array containing the input value, or the input value itself if it is already an array.
* @example
* ```ts
* castArray('foo'); // ['foo']
* castArray(['foo']); // ['foo']
* castArray(null); // []
* castArray(undefined); // []
* ```
*/
declare function castArray<T>(value: null): T[];
/**
* Casts the input value to an array if it is not already an array.
* @param value The input value to cast to an array.
* @returns An array containing the input value, or the input value itself if it is already an array.
* @example
* ```ts
* castArray('foo'); // ['foo']
* castArray(['foo']); // ['foo']
* castArray(null); // []
* castArray(undefined); // []
* ```
*/
declare function castArray<T>(value: undefined): T[];
/**
* Casts the input value to an array if it is not already an array.
* @param value The input value to cast to an array.
* @returns An array containing the input value, or the input value itself if it is already an array.
* @example
* ```ts
* castArray('foo'); // ['foo']
* castArray(['foo']); // ['foo']
* castArray(null); // []
* castArray(undefined); // []
* ```
*/
declare function castArray<T>(value: readonly T[]): readonly T[];
/**
* Casts the input value to an array if it is not already an array.
* @param value The input value to cast to an array.
* @returns An array containing the input value, or the input value itself if it is already an array.
* @example
* ```ts
* castArray('foo'); // ['foo']
* castArray(['foo']); // ['foo']
* castArray(null); // []
* castArray(undefined); // []
* ```
*/
declare function castArray<T>(value: T[]): T[];
/**
* Casts the input value to an array if it is not already an array.
* @param value The input value to cast to an array.
* @returns An array containing the input value, or the input value itself if it is already an array.
* @example
* ```ts
* castArray('foo'); // ['foo']
* castArray(['foo']); // ['foo']
* castArray(null); // []
* castArray(undefined); // []
* ```
*/
declare function castArray<T>(value: Maybe<Many<NonNullable<T>, 'mutable'> | Many<NonNullable<T>, 'immutable'>>): T[];
/**
* Casts the input value to an array if it is not already an array.
* @param value The input value to cast to an array.
* @returns An array containing the input value, or the input value itself if it is already an array.
* @example
* ```ts
* castArray('foo'); // ['foo']
* castArray(['foo']); // ['foo']
* castArray(null); // []
* castArray(undefined); // []
* ```
*/
declare function castArray<T>(value: NonNullable<T>): T[];
//#endregion
export { castArray as t };
//# sourceMappingURL=castArray-Bwcu9W-y.d.ts.map