source: node_modules/es-toolkit/dist/array/initial.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 * Returns an empty array when the input is a tuple containing exactly one element.
3 *
4 * @template T The type of the single element.
5 * @param {[T]} arr - A tuple containing exactly one element.
6 * @returns {[]} An empty array since there is only one element.
7 *
8 * @example
9 * const array = [100] as const;
10 * const result = initial(array);
11 * // result will be []
12 */
13declare function initial<T>(arr: readonly [T]): [];
14/**
15 * Returns an empty array when the input array is empty.
16 *
17 * @returns {[]} Always returns an empty array for an empty input.
18 *
19 * @example
20 * const array = [] as const;
21 * const result = initial(array);
22 * // result will be []
23 */
24declare function initial(arr: readonly []): [];
25/**
26 * Returns a new array containing all elements except the last one from a tuple with multiple elements.
27 *
28 * @template T The types of the initial elements.
29 * @template U The type of the last element in the tuple.
30 * @param {[...T[], U]} arr - A tuple with one or more elements.
31 * @returns {T[]} A new array containing all but the last element of the tuple.
32 *
33 * @example
34 * const array = ['apple', 'banana', 'cherry'] as const;
35 * const result = initial(array);
36 * // result will be ['apple', 'banana']
37 */
38declare function initial<T, U>(arr: readonly [...T[], U]): T[];
39/**
40 * Returns a new array containing all elements except the last one from the input array.
41 * If the input array is empty or has only one element, the function returns an empty array.
42 *
43 * @template T The type of elements in the array.
44 * @param {T[]} arr - The input array.
45 * @returns {T[]} A new array containing all but the last element of the input array.
46 *
47 * @example
48 * const arr = [1, 2, 3, 4];
49 * const result = initial(arr);
50 * // result will be [1, 2, 3]
51 */
52declare function initial<T>(arr: readonly T[]): T[];
53
54export { initial };
Note: See TracBrowser for help on using the repository browser.