initial
Import from @varavel/vdl-plugin-sdk/utils/arrays.
Utility functions re-exported from es-toolkit (MIT License).
See https://github.com/toss/es-toolkit for more details.
Call Signature
Returns an empty array when the input is a tuple containing exactly one element.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of the single element. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr |
readonly [T] |
A tuple containing exactly one element. |
Returns
[]
An empty array since there is only one element.
Example
Call Signature
Returns an empty array when the input array is empty.
Parameters
| Parameter | Type |
|---|---|
arr |
readonly [] |
Returns
[]
Always returns an empty array for an empty input.
Example
Call Signature
Returns a new array containing all elements except the last one from a tuple with multiple elements.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The types of the initial elements. |
U |
The type of the last element in the tuple. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr |
readonly [T, U] |
A tuple with one or more elements. |
Returns
T[]
A new array containing all but the last element of the tuple.
Example
const array = ['apple', 'banana', 'cherry'] as const;
const result = initial(array);
// result will be ['apple', 'banana']
Call Signature
Returns a new array containing all elements except the last one from the input array. If the input array is empty or has only one element, the function returns an empty array.
Type Parameters
| Type Parameter | Description |
|---|---|
T |
The type of elements in the array. |
Parameters
| Parameter | Type | Description |
|---|---|---|
arr |
readonly T[] |
The input array. |
Returns
T[]
A new array containing all but the last element of the input array.