Class: Util

Util


new Util()

The Utility Class that provides some useful methods used throughout the ODM

Methods


branch(object, path)

Query an object with a function

Parameters:
Name Type Argument Description
object Object | Array
path String <repeatable>
Returns:
Type
*

is(object, type)

Checks the type of an object. valid type values are: number, string, undefined, object, array and RegExp, ArrayBuffer, null, boolean plus all other [object *] types

Parameters:
Name Type Description
object *

The object to test against a type

type string | Array.<string>

All possible types that will result in a true

Returns:
Type
boolean

isArray(arrayObject)

Checks the input parameter and returns true if it is an array

Parameters:
Name Type Description
arrayObject *
Returns:
Type
boolean

objectKeys(object)

Get only the keys of an object

Parameters:
Name Type Description
object Object

The objects to get the keys from

Returns:

An array of keys

Type
Array

objectKeysPolyfill(object)

Polyfill for Object.keys

Parameters:
Name Type Description
object Object

The objects to get the keys from

Returns:

An array of keys

Type
Array

projectElement(projection, element [, parentElement])

Projects an element to a projectionDefinition

Parameters:
Name Type Argument Description
projection object

The projection definition object

element object

The element that is projected from

parentElement object <optional>

for internal recursion purpose

Returns:

The projected element

Type
object
Example
jsonOdm.util.projectElement({
    key1:'value1',
    key2:'value2'
},{
    key1:1,
    key12:function(element){return element.key1 + element.key2}
    // only field modifying queries are allowed
    key2:collection.$query.$branch("key2").$substr(0,3)
})
// will return {key1:'value1',key12:'value1value2',key2:'val'}