ObjectUtil
Index
Constructors
constructor
Returns default
Methods
staticdepthTraverse
Performs a naive depth traversal of an object / array. The data structure must not have circular references. The result of the callback function is used to modify in place the given data.
Parameters
data: any
An object or array.
func: any
A callback function to process leaf values in children arrays or object members.
modify: boolean = false
If true then the result of the callback function is used to modify in place the given data.
Returns any
staticgetAccessorList
Returns a list of accessor keys by traversing the given object.
Parameters
data: any
An object to traverse for accessor keys.
Returns any[]
staticsafeAccess
Provides a way to safely access an objects data / entries given an accessor string which describes the entries to walk. To access deeper entries into the object format the accessor string with
.
between entries to walk.Parameters
data: any
An object to access entry data.
accessor: string
A string describing the entries to access.
optionaldefaultValue: any
(Optional) A default value to return if an entry for accessor is not found.
Returns any
staticsafeBatchSet
Provides a way to safely batch set an objects data / entries given an array of accessor strings which describe the entries to walk. To access deeper entries into the object format the accessor string with
.
between entries to walk. If value is an object the accessor will be used to access a target value fromvalue
which is subsequently set todata
by the given operation. Ifvalue
is not an object it will be used as the target value to set across all accessors.Parameters
data: any
An object to access entry data.
accessors: string[]
A string describing the entries to access.
value: any
A new value to set if an entry for accessor is found.
operation: string = "set"
Operation to perform including: ‘add’, ‘div’, ‘mult’, ‘set’, ‘set-undefined’, ‘sub’.
defaultAccessValue: any = 0
A new value to set if an entry for accessor is found.
createMissing: boolean = true
If true missing accessor entries will be created as objects automatically.
Returns void
staticsafeEqual
Compares a source object and values of entries against a target object. If the entries in the source object match the target object then
true
is returned otherwisefalse
. If either object is undefined or null then false is returned.Parameters
source: any
Source object.
target: any
Target object.
Returns boolean
staticsafeSet
Provides a way to safely set an objects data / entries given an accessor string which describes the entries to walk. To access deeper entries into the object format the accessor string with
.
between entries to walk.Parameters
data: any
An object to access entry data.
accessor: string
A string describing the entries to access.
value: any
A new value to set if an entry for accessor is found.
operation: string = "set"
Operation to perform including: ‘add’, ‘div’, ‘mult’, ‘set’, ‘set-undefined’, ‘sub’.
createMissing: boolean = true
If true missing accessor entries will be created as objects automatically.
Returns boolean
staticsafeSetAll
Performs bulk setting of values to the given data object.
Parameters
data: any
The data object to set data.
accessorValues: {}
Object of accessor keys to values to set.
operation: string = "set"
Operation to perform including: ‘add’, ‘div’, ‘mult’, ‘set’, ‘sub’; default (
set
).createMissing: boolean = true
If true missing accessor entries will be created as objects automatically.
Returns void
staticvalidate
Performs bulk validation of data given an object,
validationData
, which describes all entries to test.Parameters
data: any
The data object to test.
validationData: any = {}
Key is the accessor / value is a validation entry. (object<string, ValidationEntry>)
dataName: string = "data"
Optional name of data.
Returns boolean
staticvalidateArray
Validates all array entries against potential type and expected tests.
Parameters
data: any
The data object to test.
accessor: string
A string describing the entries to access.
options: ValidateArrayOptions = {}
?
dataName: string = "data"
Optional name of data. (“data”)
Returns boolean
staticvalidateEntry
Validates data entry with a typeof check and potentially tests against the values in any given expected set.
Parameters
data: any
The object data to validate.
accessor: string
A string describing the entries to access.
options: ValidateArrayOptions
?
dataName: string = "data"
Optional name of data.
Returns boolean
staticvalidateEntryOrArray
Dispatches validation of data entry to string or array validation depending on data entry type.
Parameters
data: any
The data object to test.
accessor: string
A string describing the entries to access.
entry: ValidateArrayOptions
A validation entry.
dataName: string = "data"
Optional name of data.
Returns boolean
Provides common object manipulation utilities including depth traversal, obtaining accessors, safely setting values / equality tests, and validation.
Support for @ponticus/plugin-manager is enabled.