Skip to main content

@terascope/utils / arrays

arrays

Functions

castArray()

castArray<T>(input): T[]

A simplified implementation of lodash castArray

Type parameters

Type parameter
T

Parameters

ParameterType
inputundefined | null | T | T[] | readonly T[]

Returns

T[]

Source

packages/utils/src/arrays.ts:22


chunk()

chunk<T>(dataArray, size): T[][]

Chunk an array into specific sizes

Type parameters

Type parameter
T

Parameters

ParameterType
dataArrayIterable<T>
sizenumber

Returns

T[][]

Source

packages/utils/src/arrays.ts:130


chunkIter()

chunkIter<T>(dataArray, size): Iterable<T[]>

Chunk an array into specific size, by using an iterator

Type parameters

Type parameter
T

Parameters

ParameterType
dataArrayIterable<T>
sizenumber

Returns

Iterable<T[]>

Source

packages/utils/src/arrays.ts:135


concat()

concat(arr, arr1)

concat<T>(arr, arr1?): readonly T[]

Concat and unique the items in the array Any non-array value will be converted to an array

Type parameters
Type parameter
T
Parameters
ParameterType
arrT | T[]
arr1?T | T[]
Returns

readonly T[]

Source

packages/utils/src/arrays.ts:33

concat(arr, arr1)

concat<T>(arr, arr1?): readonly T[]

Type parameters
Type parameter
T
Parameters
ParameterType
arrreadonly T[]
arr1?readonly T[]
Returns

readonly T[]

Source

packages/utils/src/arrays.ts:34

concat(arr, arr1)

concat<T>(arr, arr1?): readonly T[]

Type parameters
Type parameter
T
Parameters
ParameterType
arrreadonly T[]
arr1?T | T[]
Returns

readonly T[]

Source

packages/utils/src/arrays.ts:35


flatten()

flatten<T>(val): T[]

A native implementation of lodash flatten

Type parameters

Type parameter
T

Parameters

ParameterType
valMany<T[]>

Returns

T[]

Source

packages/utils/src/arrays.ts:8


flattenDeep()

flattenDeep<T>(val): T[]

Type parameters

Type parameter
T

Parameters

ParameterType
valListOfRecursiveArraysOrValues<T>

Returns

T[]

Source

packages/utils/src/arrays.ts:12


getFirst()

getFirst<T>(input): T | undefined

If the input is an array it will return the first item else if it will return the input

Type parameters

Type parameter
T

Parameters

ParameterType
inputT | T[] | readonly T[]

Returns

T | undefined

Source

packages/utils/src/arrays.ts:187


getLast()

getLast<T>(input): T | undefined

If the input is an array it will return the first item else if it will return the input

Type parameters

Type parameter
T

Parameters

ParameterType
inputT | T[] | readonly T[]

Returns

T | undefined

Source

packages/utils/src/arrays.ts:195


includes()

includes(input, key): boolean

Safely check if an array, object, map, set has a key

Parameters

ParameterType
inputunknown
keystring

Returns

boolean

Source

packages/utils/src/arrays.ts:172


isArray()

isArray<T>(input): input is T

Check if an input is an array, just Array.isArray

Type parameters

Type parameterValue
Tany[]

Parameters

ParameterType
inputunknown

Returns

input is T

Source

packages/utils/src/arrays.ts:202


isArrayLike()

isArrayLike<T>(input): input is T

Check if an input is an TypedArray or Array instance

Type parameters

Type parameterValue
Tany[]

Parameters

ParameterType
inputunknown

Returns

input is T

Source

packages/utils/src/arrays.ts:217


isTypedArray()

isTypedArray<T>(input): input is T

Check if an input is an TypedArray instance like: Uint8Array or Uint16Array. This excludes nodejs Buffers since they aren't really the same.

Type parameters

Type parameterValue
TTypedArray

Parameters

ParameterType
inputunknown

Returns

input is T

Source

packages/utils/src/arrays.ts:210


sort()

sort<T>(arr, compare?): T[]

Sort an arr or set

Type parameters

Type parameter
T

Parameters

ParameterType
arrSet<T> | T[] | readonly T[]
compare?(a, b) => number

Returns

T[]

Source

packages/utils/src/arrays.ts:50


sortBy()

sortBy<T, V>(arr, fnOrPath): T[]

Sort by path or function that returns the values to sort with

Type parameters

Type parameterValue
T-
Vany

Parameters

ParameterType
arrSet<T> | T[]
fnOrPathstring | (value) => V

Returns

T[]

Source

packages/utils/src/arrays.ts:65


times()

times(n)

times(n): number[]

A native implementation of lodash times

Parameters
ParameterType
nnumber
Returns

number[]

Source

packages/utils/src/arrays.ts:112

times(n, fn)

times<T>(n, fn): T[]

Type parameters
Type parameter
T
Parameters
ParameterType
nnumber
fn(index) => T
Returns

T[]

Source

packages/utils/src/arrays.ts:113


timesIter()

timesIter(n)

timesIter(n): Iterable<number>

Like times but an iterable

Parameters
ParameterType
nnumber
Returns

Iterable<number>

Source

packages/utils/src/arrays.ts:120

timesIter(n, fn)

timesIter<T>(n, fn): Iterable<T>

Type parameters
Type parameter
T
Parameters
ParameterType
nnumber
fn(index) => T
Returns

Iterable<T>

Source

packages/utils/src/arrays.ts:121


uniq()

uniq<T>(arr): T[]

A native implementation of lodash uniq

Type parameters

Type parameter
T

Parameters

ParameterType
arrT[] | Set<T>

Returns

T[]

Source

packages/utils/src/arrays.ts:44


uniqBy()

uniqBy<T, V>(values, fnOrPath): T[]

Get the unique values by a path or function that returns the unique values

Type parameters

Type parameterValue
T-
Vany

Parameters

ParameterType
valuesT[] | readonly T[]
fnOrPathstring | (value) => V

Returns

T[]

Source

packages/utils/src/arrays.ts:95