@terascope/utils / arrays
arrays
Functions
castArray()
castArray<
T
>(input
):T
[]
A simplified implementation of lodash castArray
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
input | undefined | 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
Parameter | Type |
---|---|
dataArray | Iterable <T > |
size | number |
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
Parameter | Type |
---|---|
dataArray | Iterable <T > |
size | number |
Returns
Iterable
<T
[]>
Source
packages/utils/src/arrays.ts:135
concat()
concat(arr, arr1)
concat<
T
>(arr
,arr1
?): readonlyT
[]
Concat and unique the items in the array Any non-array value will be converted to an array
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
arr | T | T [] |
arr1 ? | T | T [] |
Returns
readonly T
[]
Source
packages/utils/src/arrays.ts:33
concat(arr, arr1)
concat<
T
>(arr
,arr1
?): readonlyT
[]
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
arr | readonly T [] |
arr1 ? | readonly T [] |
Returns
readonly T
[]
Source
packages/utils/src/arrays.ts:34
concat(arr, arr1)
concat<
T
>(arr
,arr1
?): readonlyT
[]
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
arr | readonly 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
Parameter | Type |
---|---|
val | Many <T []> |
Returns
T
[]
Source
packages/utils/src/arrays.ts:8
flattenDeep()
flattenDeep<
T
>(val
):T
[]
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
val | ListOfRecursiveArraysOrValues <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
Parameter | Type |
---|---|
input | T | 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
Parameter | Type |
---|---|
input | T | 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
Parameter | Type |
---|---|
input | unknown |
key | string |
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 parameter | Value |
---|---|
T | any [] |
Parameters
Parameter | Type |
---|---|
input | unknown |
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 parameter | Value |
---|---|
T | any [] |
Parameters
Parameter | Type |
---|---|
input | unknown |
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 parameter | Value |
---|---|
T | TypedArray |
Parameters
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
arr | Set <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 parameter | Value |
---|---|
T | - |
V | any |
Parameters
Parameter | Type |
---|---|
arr | Set <T > | T [] |
fnOrPath | string | (value ) => V |
Returns
T
[]
Source
packages/utils/src/arrays.ts:65
times()
times(n)
times(
n
):number
[]
A native implementation of lodash times
Parameters
Parameter | Type |
---|---|
n | number |
Returns
number
[]
Source
packages/utils/src/arrays.ts:112
times(n, fn)
times<
T
>(n
,fn
):T
[]
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
n | number |
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
Parameter | Type |
---|---|
n | number |
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
Parameter | Type |
---|---|
n | number |
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
Parameter | Type |
---|---|
arr | T [] | 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 parameter | Value |
---|---|
T | - |
V | any |
Parameters
Parameter | Type |
---|---|
values | T [] | readonly T [] |
fnOrPath | string | (value ) => V |
Returns
T
[]