UNPKG

typedash

Version:

modern, type-safe collection of utility functions

84 lines (81 loc) 2.81 kB
import { M as Many } from '../Many-Dnn8Ysh_.cjs'; import { M as Maybe } from '../Maybe-D6dwMjD9.cjs'; /** * 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[]; export { castArray };