UNPKG

typedash

Version:

modern, type-safe collection of utility functions

73 lines (70 loc) 3.78 kB
import { M as Many } from '../Many-Dnn8Ysh_.js'; import { M as Maybe } from '../Maybe-D6dwMjD9.js'; /** * 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[]>; export { castArrayIfDefined };