Skip to content

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

function initial<T>(arr): [];

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

const array = [100] as const;
const result = initial(array);
// result will be []

Call Signature

function initial(arr): [];

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

const array = [] as const;
const result = initial(array);
// result will be []

Call Signature

function initial<T, U>(arr): T[];

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

function initial<T>(arr): T[];

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.

Example

const arr = [1, 2, 3, 4];
const result = initial(arr);
// result will be [1, 2, 3]