Skip to main content

@terascope/utils / objects

objects

Functions

fastAssign()

fastAssign<T, U>(target, source): T & U

Perform a shallow clone of an object to another, in the fastest way possible

Type parameters

Type parameter
T extends object
U extends object

Parameters

ParameterType
targetT
sourceU

Returns

T & U

Source

packages/utils/src/objects.ts:58


fastCloneDeep()

fastCloneDeep<T>(input): T

A clone deep using JSON.parse(JSON.stringify(input))

Type parameters

Type parameter
T

Parameters

ParameterType
inputT

Returns

T

Source

packages/utils/src/objects.ts:53


filterObject()

filterObject<T, I, E>(data, by?): FilteredResult<T, I, E>

Filters the keys of an object, by list of included key and excluded

Type parameters

Type parameter
T extends object
I extends string | number | symbol
E extends string | number | symbol

Parameters

ParameterType
dataT
by?object
by.excludes?E[]
by.includes?I[]

Returns

FilteredResult<T, I, E>

Source

packages/utils/src/objects.ts:135


getField()

getField(input, field, defaultVal)

getField<V>(input, field, defaultVal?): V

A type safe get function (will always return the correct type)

IMPORTANT This does not behave like lodash.get, it does not deal with dot notation (nested fields) and it will use the default when dealing with OR statements

Type parameters
Type parameter
V
Parameters
ParameterType
inputundefined
fieldstring
defaultVal?V
Returns

V

Source

packages/utils/src/objects.ts:170

getField(input, field)

getField<T, P>(input, field): T[P]

Type parameters
Type parameter
T
P extends string | number | symbol
Parameters
ParameterType
inputT
fieldP
Returns

T[P]

Source

packages/utils/src/objects.ts:175

getField(input, field)

getField<T, P>(input, field): T[P]

Type parameters
Type parameter
T
P extends string | number | symbol
Parameters
ParameterType
inputundefined | T
fieldP
Returns

T[P]

Source

packages/utils/src/objects.ts:179

getField(input, field, defaultVal)

getField<T, P>(input, field, defaultVal): T[P]

Type parameters
Type parameter
T
P extends string | number | symbol
Parameters
ParameterType
inputundefined | T
fieldP
defaultValnever[]
Returns

T[P]

Source

packages/utils/src/objects.ts:183

getField(input, field, defaultVal)

getField<T, P, V>(input, field, defaultVal): T[P] | V

Type parameters
Type parameter
T
P extends string | number | symbol
V
Parameters
ParameterType
inputundefined | T
fieldP
defaultValV
Returns

T[P] | V

Source

packages/utils/src/objects.ts:188

getField(input, field, defaultVal)

getField<T, P, V>(input, field, defaultVal): T[P]

Type parameters
Type parameter
T
P extends string | number | symbol
V
Parameters
ParameterType
inputundefined | T
fieldP
defaultValV
Returns

T[P]

Source

packages/utils/src/objects.ts:193


getFirstKey()

getFirstKey<T>(input): keyof T | undefined

Get the first key in an object

Type parameters

Type parameter
T extends object

Parameters

ParameterType
inputT

Returns

keyof T | undefined

Source

packages/utils/src/objects.ts:32


getFirstValue()

getFirstValue<T>(input): T | undefined

Get the first value in an object

Type parameters

Type parameter
T

Parameters

ParameterType
inputobject

Returns

T | undefined

Source

packages/utils/src/objects.ts:25


hasOwn()

hasOwn(obj, prop): boolean

Check if a object has property (and not included in the prototype) Different from has since it doesn't deal with dot notation values.

Parameters

ParameterType
objany
propstring | number | symbol

Returns

boolean

Source

packages/utils/src/objects.ts:215


isKey()

isKey<T>(O, k): k is keyof T

Verify that k is a key of object O

Type parameters

Type parameter
T extends object

Parameters

ParameterType
OT
kPropertyKey

Returns

k is keyof T

Source

packages/utils/src/objects.ts:39


isObjectEntity()

isObjectEntity(input): boolean

Verify if the input is a object like type

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/objects.ts:46


isSimpleObject()

isSimpleObject(input): input is Record<string, unknown>

Similar to is-plain-object but works better when you cloneDeep a DataEntity

Parameters

ParameterType
inputunknown

Returns

input is Record<string, unknown>

Source

packages/utils/src/objects.ts:13


lookup()

lookup(input): (key) => any

Parameters

ParameterType
inputunknown

Returns

Function

Parameters
ParameterType
keyunknown
Returns

any

Source

packages/utils/src/objects.ts:219


mapKeys()

mapKeys<T, R>(input, fn): R

Map the keys of an object

Type parameters

Type parameterValue
T extends object-
RT

Parameters

ParameterType
inputT
fn(value, key) => any

Returns

R

Source

packages/utils/src/objects.ts:105


mapValues()

mapValues<T, R>(input, fn): R

Map the values of an object

Type parameters

Type parameterValue
T extends object-
RT

Parameters

ParameterType
inputT
fn(value, key) => any

Returns

R

Source

packages/utils/src/objects.ts:91


sortKeys()

sortKeys<T>(input, options): T

Sort keys on an object

Type parameters

Type parameter
T extends Record<string, unknown>

Parameters

ParameterType
inputT
optionsobject
options.deep?boolean

Returns

T

Source

packages/utils/src/objects.ts:71


withoutNil()

withoutNil<T>(input): WithoutNil<T>

Build a new object without null or undefined values (shallow)

Type parameters

Type parameter
T

Parameters

ParameterType
inputT

Returns

WithoutNil<T>

Source

packages/utils/src/objects.ts:119