obj.js
Methods
-
staticmodule:obj.defineLazyProperty(obj, key, getValue, setter)
-
Object.defineProperty but "lazy", which means that the value is only set after it is retrieved the first time, rather than being set right away.
Name Type Description obj
Object the object to set the property on
key
string the key for the property to set
getValue
function the function used to get the value when it is needed.
setter
boolean whether a setter should be allowed or not
-
staticmodule:obj.each(object, fn)
-
Array-like iteration for objects.
Name Type Description object
Object The object to iterate over
fn
obj:EachCallback The callback function which is called for each key in the object.
-
staticmodule:obj.isObject(value){boolean}
-
Returns whether a value is an object of any kind - including DOM nodes, arrays, regular expressions, etc. Not functions, though.
This avoids the gotcha where using
typeof
on anull
value results in'object'
.Name Type Description value
Object Returns:
Type Description boolean -
staticmodule:obj.isPlain(value){boolean}
-
Returns whether an object appears to be a "plain" object - that is, a direct instance of
Object
.Name Type Description value
Object Returns:
Type Description boolean -
staticmodule:obj.merge(sources){Object}
-
Merge two objects recursively.
Performs a deep merge like lodash.merge, but only merges plain objects (not arrays, elements, or anything else).
Non-plain object values will be copied directly from the right-most argument.
Name Type Description sources
Array.<Object> One or more objects to merge into a new object.
Returns:
Type Description Object A new object that is the merged result of all sources. -
staticmodule:obj.reduce(object, fn, initial){*}
-
Array-like reduce for objects.
Name Type Default Description object
Object The Object that you want to reduce.
fn
function A callback function which is called for each key in the object. It receives the accumulated value and the per-iteration value and key as arguments.
initial
* 0 optional Starting value
Returns:
Type Description * The final accumulated value. -
staticmodule:obj.values(source){Array.<unknown>}
-
Returns an array of values for a given object
Name Type Description source
Object target object
Returns:
Type Description Array.<unknown> - object values
Type Definitions
-
obj:EachCallback(value, key)
-
Name Type Description value
* The current key for the object that is being iterated over.
key
string The current key-value for object that is being iterated over
-
obj:ReduceCallback(accum, value, key){*}
-
Name Type Description accum
* The value that is accumulating over the reduce loop.
value
* The current key for the object that is being iterated over.
key
string The current key-value for object that is being iterated over
Returns:
Type Description * The new accumulated value.