requireArray()function

requireArray(arr: MutableArray<T>, min: 1, max: 1, caller?: AnyCaller): [T]
requireArray(arr: MutableArray<T>, min: 2, max: 2, caller?: AnyCaller): [T, T]
requireArray(arr: MutableArray<T>, min: 3, max: 3, caller?: AnyCaller): [T, T, T]
requireArray(arr: MutableArray<T>, min?: 1, max?: number, caller?: AnyCaller): [T, ...T[]]
requireArray(arr: MutableArray<T>, min: 2, max?: number, caller?: AnyCaller): [T, T, ...T[]]
requireArray(arr: MutableArray<T>, min: 3, max?: number, caller?: AnyCaller): [T, T, T, ...T[]]
requireArray(arr: MutableArray<T>, min?: number, max?: number, caller?: AnyCaller): MutableArray<T>
requireArray(arr: ImmutableArray<T>, min: 1, max: 1, caller?: AnyCaller): readonly [T]
requireArray(arr: ImmutableArray<T>, min: 2, max: 2, caller?: AnyCaller): readonly [T, T]
requireArray(arr: ImmutableArray<T>, min: 3, max: 3, caller?: AnyCaller): readonly [T, T, T]
requireArray(arr: ImmutableArray<T>, min?: 1, max?: number, caller?: AnyCaller): readonly [T, ...T[]]
requireArray(arr: ImmutableArray<T>, min: 2, max?: number, caller?: AnyCaller): readonly [T, T, ...T[]]
requireArray(arr: ImmutableArray<T>, min: 3, max?: number, caller?: AnyCaller): readonly [T, T, T, ...T[]]
requireArray(list: PossibleArray<T>, min?: number, max?: number, caller?: AnyCaller): ImmutableArray<T>
ParamType
arrMutableArray<T>
Mutable array: an array that can be changed. required
min1
Minimum number of items the array must contain (defaults to 0). required
max1
Maximum number of items the array may contain (defaults to Infinity). required
callerAnyCaller
Function to attribute a thrown error to (defaults to requireArray itself).
min2
required
max2
required
callerAnyCaller
Any calling function or constructor, usually referring to something that can call in the current scope that can appear in a stack trace.
min3
required
max3
required
min1
maxnumber
minnumber
arrImmutableArray<T>
Immutable array: an array that cannot be changed. required
min1
required
max1
required
listPossibleArray<T>
Things that can be converted to arrays. required
Return
[T]
An array of the items within the length bounds.
[T, T]
[T, T, T]
[T, ...T[]]
[T, T, ...T[]]
[T, T, T, ...T[]]
MutableArray<T>
Mutable array: an array that can be changed.
readonly [T]
readonly [T, T]
readonly [T, T, T]
readonly [T, ...T[]]
readonly [T, T, ...T[]]
readonly [T, T, T, ...T[]]
ImmutableArray<T>
Immutable array: an array that cannot be changed.
Throws
RequiredError
If list cannot be converted to an array within the length bounds.

Convert a possible array to an array (optionally with specified min/max length), or throw RequiredError if conversion fails.

Examples

requireArray(new Set([1, 2])); // [1, 2]
requireArray([], 1); // throws RequiredError