//#region src/array/arrayify.d.ts /** * Ensures a value is an array: returns it unchanged when it already is one, * wraps it in a single-element array otherwise, and — by default — returns an * empty array for nullish input (`null` / `undefined`). Note that this *wraps* * rather than *converts* — passing an iterable like a `Set` yields `[set]`, not * its spread contents (use `Array.from` for that). * * Two things make it sharper than a plain cast: precise typing (an existing * array — including a tuple — keeps its exact type, any other value widens to * `value[]`), and nullish values collapse to `[]` rather than being wrapped as * `[null]` / `[undefined]`. Pass `shouldWrapNullish: true` to opt back into * wrapping nullish values like any other value. * @param value - The value to ensure is an array. * @param shouldWrapNullish - When `true`, a nullish `value` is wrapped (`[value]`) * like any other value instead of collapsing to `[]`. Defaults to `false`. * @returns The original array, a new single-element array wrapping `value`, or * an empty array when `value` is nullish and `shouldWrapNullish` is `false`. * @example * // Wraps a non-array * arrayify(1); * // [1] * @example * // Returns an existing array untouched (preserving tuple types) * arrayify([1, 2, 3]); * // [1, 2, 3] * @example * // Wraps rather than converts — a Set is not spread * arrayify(new Set([1, 2, 3])); * // [Set(3) {1, 2, 3}] * @example * // Nullish input collapses to an empty array by default * arrayify(undefined); * // [] * arrayify(null); * // [] * @example * // ...unless `shouldWrapNullish` opts into treating it like any other value * arrayify(null, true); * // [null] * arrayify(undefined, true); * // [undefined] */ declare function arrayify(value: T, shouldWrapNullish: true): [T]; declare function arrayify(value: T, shouldWrapNullish: true): T; declare function arrayify(value: T | readonly T[], shouldWrapNullish: true): NonNullable[]; declare function arrayify(value: T, shouldWrapNullish: true): NonNullable[]; declare function arrayify(value: null | undefined, shouldWrapNullish?: boolean): []; declare function arrayify(value: T | null | undefined, shouldWrapNullish?: boolean): T; declare function arrayify(value: T | readonly T[] | null | undefined, shouldWrapNullish?: boolean): NonNullable[]; declare function arrayify(value: T | null | undefined, shouldWrapNullish?: boolean): NonNullable[]; //#endregion export { arrayify };