@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
Parameter | Type |
---|---|
target | T |
source | U |
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
Parameter | Type |
---|---|
input | T |
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
Parameter | Type |
---|---|
data | T |
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
Parameter | Type |
---|---|
input | undefined |
field | string |
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
Parameter | Type |
---|---|
input | T |
field | P |
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
Parameter | Type |
---|---|
input | undefined | T |
field | P |
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
Parameter | Type |
---|---|
input | undefined | T |
field | P |
defaultVal | never [] |
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
Parameter | Type |
---|---|
input | undefined | T |
field | P |
defaultVal | V |
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
Parameter | Type |
---|---|
input | undefined | T |
field | P |
defaultVal | V |
Returns
T
[P
]
Source
packages/utils/src/objects.ts:193
getFirstKey()
getFirstKey<
T
>(input
): keyofT
|undefined
Get the first key in an object
Type parameters
Type parameter |
---|
T extends object |
Parameters
Parameter | Type |
---|---|
input | T |
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
Parameter | Type |
---|---|
input | object |
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
Parameter | Type |
---|---|
obj | any |
prop | string | 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
Parameter | Type |
---|---|
O | T |
k | PropertyKey |
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
Parameter | Type |
---|---|
input | unknown |
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
Parameter | Type |
---|---|
input | unknown |
Returns
input is Record<string, unknown>
Source
packages/utils/src/objects.ts:13
lookup()
lookup(
input
): (key
) =>any
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
Function
Parameters
Parameter | Type |
---|---|
key | unknown |
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 parameter | Value |
---|---|
T extends object | - |
R | T |
Parameters
Parameter | Type |
---|---|
input | T |
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 parameter | Value |
---|---|
T extends object | - |
R | T |
Parameters
Parameter | Type |
---|---|
input | T |
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
Parameter | Type |
---|---|
input | T |
options | object |
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
Parameter | Type |
---|---|
input | T |
Returns
WithoutNil
<T
>