UNPKG

typedash

Version:

modern, type-safe collection of utility functions

74 lines (73 loc) 3.92 kB
import { t as Many } from "./Many-bCNxekD7.cjs"; import { t as Maybe } from "./Maybe-BVpZiDsE.cjs"; //#region src/functions/castArrayIfDefined/castArrayIfDefined.d.ts /** * Converts the given value to an array if it's not already one, or returns an value as-is if it's not defined (i.e. `null` or `undefined`). * @note If the value is already an array, it is returned as-is (same reference). * @param value The value to convert to an array if it's not already one. * @returns An array containing the input value, or the input value itself if it is already an array, or `null` or `undefined` if the input value is `null` or `undefined`. * @example * ```ts * castArrayIfDefined(null) // null * ``` */ declare function castArrayIfDefined(value: null): null; /** * Converts the given value to an array if it's not already one, or returns an value as-is if it's not defined (i.e. `null` or `undefined`). * @note If the value is already an array, it is returned as-is (same reference). * @param value The value to convert to an array if it's not already one. * @example * ```ts * castArrayIfDefined(undefined) // undefined * ``` */ declare function castArrayIfDefined(value: undefined): undefined; /** * Converts the given value to an array if it's not already one, or returns an value as-is if it's not defined (i.e. `null` or `undefined`). * @note If the value is already an array, it is returned as-is (same reference). * @param value The value to convert to an array if it's not already one. * @returns An array containing the input value, or the input value itself if it is already an array, or `null` or `undefined` if the input value is `null` or `undefined`. * @example * ```ts * castArrayIfDefined([1, 2, 3]) // [1, 2, 3] * ``` */ declare function castArrayIfDefined<T>(value: readonly T[]): readonly T[]; /** * Converts the given value to an array if it's not already one, or returns an value as-is if it's not defined (i.e. `null` or `undefined`). * @note If the value is already an array, it is returned as-is (same reference). * @param value The value to convert to an array if it's not already one. * @returns An array containing the input value, or the input value itself if it is already an array, or `null` or `undefined` if the input value is `null` or `undefined`. * @example * ```ts * castArrayIfDefined([1, 2, 3]) // [1, 2, 3] * ``` */ declare function castArrayIfDefined<T>(value: T[]): T[]; /** * Converts the given value to an array if it's not already one, or returns an value as-is if it's not defined (i.e. `null` or `undefined`). * @note If the value is already an array, it is returned as-is (same reference). * @param value The value to convert to an array if it's not already one. * @returns An array containing the input value, or the input value itself if it is already an array, or `null` or `undefined` if the input value is `null` or `undefined`. * @example * ```ts * castArrayIfDefined([1, 2, 3]) // [1, 2, 3] * castArrayIfDefined(42) // [42] * ``` */ declare function castArrayIfDefined<T>(value: NonNullable<T>): T[]; /** * Converts the given value to an array if it's not already one, or returns an value as-is if it's not defined (i.e. `null` or `undefined`). * @note If the value is already an array, it is returned as-is (same reference). * @param value The value to convert to an array if it's not already one. * @returns An array containing the input value, or the input value itself if it is already an array, or `null` or `undefined` if the input value is `null` or `undefined`. * @example * ```ts * castArrayIfDefined([1, 2, 3]) // [1, 2, 3] * castArrayIfDefined(42) // [42] * ``` */ declare function castArrayIfDefined<T>(value: Maybe<Many<NonNullable<T>, 'mutable'> | Many<NonNullable<T>, 'immutable'>>): Maybe<T[]>; //#endregion export { castArrayIfDefined as t }; //# sourceMappingURL=castArrayIfDefined--nX6gSRW.d.cts.map