StaticcompileStaticdict'dict' function
Returns a (pointer -> value) dictionary for an object
// { object } object - The object to create a dictionary from // { object } - The resulting dictionary object
Staticescape'escape' function
Escapes a string reference key
// { string } key - string key to escape // { string } - escaped key
StaticevaluateEvaluates conditional expression in form of model.<property>==<value> or
model.<property>!=<value> where the first one means that the value must match to be
shown in a form, while the former shows the property only when the property value is not
set, or does not equal the given value.
// { subObject } subObject - an object containing the data values of properties
// { key } key - the key from the for loop in a form of <property>==<value>
Returns the object with two properties. The property passed informs whether the expression evaluated successfully and the property key returns either the same key if it is not contained inside the subObject or the key of the property if it is contained.
Staticfor'forEachDeep' function
Iterates over own enumerable properties of an object or items in an array and invokes an iteratee function for each key/value or index/value pair. By default, iterates over items within objects and arrays after calling the iteratee function on the containing object or array itself.
The iteratee is invoked with three arguments: (value, pointer, rootObject), where pointer is a JSON pointer indicating the location of the current value within the root object, and rootObject is the root object initially submitted to th function.
If a third optional parameter 'bottomUp' is set to TRUE, the iterator function will be called on sub-objects and arrays after being called on their contents, rather than before, which is the default.
This function can also optionally be called directly on a sub-object by including optional 4th and 5th parameterss to specify the initial root object and pointer.
// { object } object - the initial object or array // { (v: any, p?: string, o?: any) => any } function - iteratee function // { boolean = false } bottomUp - optional, set to TRUE to reverse direction // { object = object } rootObject - optional, root object or array // { string = '' } pointer - optional, JSON Pointer to object within rootObject // { object } - The modified object
Staticfor'forEachDeepCopy' function
Similar to forEachDeep, but returns a copy of the original object, with the same keys and indexes, but with values replaced with the result of the iteratee function.
// { object } object - the initial object or array // { (v: any, k?: string, o?: any, p?: any) => any } function - iteratee function // { boolean = false } bottomUp - optional, set to TRUE to reverse direction // { object = object } rootObject - optional, root object or array // { string = '' } pointer - optional, JSON Pointer to object within rootObject // { object } - The copied object
Staticget'get' function
Uses a JSON Pointer to retrieve a value from an object.
// { object } object - Object to get value from // { Pointer } pointer - JSON Pointer (string or array) // { number = 0 } startSlice - Zero-based index of first Pointer key to use // { number } endSlice - Zero-based index of last Pointer key to use // { boolean = false } getBoolean - Return only true or false? // { boolean = false } errors - Show error if not found? // { object } - Located value (or true or false if getBoolean = true)
Staticget'getCopy' function
Uses a JSON Pointer to deeply clone a value from an object.
// { object } object - Object to get value from // { Pointer } pointer - JSON Pointer (string or array) // { number = 0 } startSlice - Zero-based index of first Pointer key to use // { number } endSlice - Zero-based index of last Pointer key to use // { boolean = false } getBoolean - Return only true or false? // { boolean = false } errors - Show error if not found? // { object } - Located value (or true or false if getBoolean = true)
Staticget'getFirst' function
Takes an array of JSON Pointers and objects, checks each object for a value specified by the pointer, and returns the first value found.
// { [object, pointer][] } items - Array of objects and pointers to check // { any = null } defaultValue - Value to return if nothing found // { boolean = false } getCopy - Return a copy instead? // - First value found
Staticget'getFirstCopy' function
Similar to getFirst, but always returns a copy.
// { [object, pointer][] } items - Array of objects and pointers to check // { any = null } defaultValue - Value to return if nothing found // - Copy of first value found
Statichas'has' function
Tests if an object has a value at the location specified by a JSON Pointer
// { object } object - object to chek for value // { Pointer } pointer - JSON Pointer (string or array) // { boolean }
Staticinsert'insert' function
Calls 'set' with insert = TRUE
// { object } object - object to insert value in // { Pointer } pointer - JSON Pointer (string or array) // value - value to insert // { object }
Staticinsert'insertCopy' function
Calls 'setCopy' with insert = TRUE
// { object } object - object to insert value in // { Pointer } pointer - JSON Pointer (string or array) // value - value to insert // { object }
Staticis'isJsonPointer' function
Checks a string or array value to determine if it is a valid JSON Pointer. Returns true if a string is empty, or starts with '/' or '#/'. Returns true if an array contains only string values.
// value - value to check // { boolean } - true if value is a valid JSON Pointer, otherwise false
Staticis'isSubPointer' function
Checks whether one JSON Pointer is a subset of another.
// { Pointer } shortPointer - potential subset JSON Pointer // { Pointer } longPointer - potential superset JSON Pointer // { boolean = false } trueIfMatching - return true if pointers match? // { boolean = false } errors - Show error if invalid pointer? // { boolean } - true if shortPointer is a subset of longPointer, false if not
Staticparse'parse' function
Converts a string JSON Pointer into a array of keys (if input is already an an array of keys, it is returned unchanged)
// { Pointer } pointer - JSON Pointer (string or array) // { boolean = false } errors - Show error if invalid pointer? // { string[] } - JSON Pointer array of keys
Staticparse'parseObjectPath' function
Parses a JavaScript object path into an array of keys, which can then be passed to compile() to convert into a string JSON Pointer.
Based on mike-marcacci's excellent objectpath parse function: https://github.com/mike-marcacci/objectpath
// { Pointer } path - The object path to parse // { string[] } - The resulting array of keys
Staticremove'remove' function
Uses a JSON Pointer to remove a key and its attribute from an object
// { object } object - object to delete attribute from // { Pointer } pointer - JSON Pointer (string or array) // { object }
Staticset'set' function
Uses a JSON Pointer to set a value on an object. Also creates any missing sub objects or arrays to contain that value.
If the optional fourth parameter is TRUE and the inner-most container is an array, the function will insert the value as a new item at the specified location in the array, rather than overwriting the existing value (if any) at that location.
So set([1, 2, 3], '/1', 4) => [1, 4, 3] and So set([1, 2, 3], '/1', 4, true) => [1, 4, 2, 3]
// { object } object - The object to set value in // { Pointer } pointer - The JSON Pointer (string or array) // value - The new value to set // { boolean } insert - insert value? // { object } - The original object, modified with the set value
Staticset'setCopy' function
Copies an object and uses a JSON Pointer to set a value on the copy. Also creates any missing sub objects or arrays to contain that value.
If the optional fourth parameter is TRUE and the inner-most container is an array, the function will insert the value as a new item at the specified location in the array, rather than overwriting the existing value.
// { object } object - The object to copy and set value in // { Pointer } pointer - The JSON Pointer (string or array) // value - The value to set // { boolean } insert - insert value? // { object } - The new object with the set value
Staticto'toControlPointer' function
Accepts a JSON Pointer for a data object and returns a JSON Pointer for the matching control in an Angular FormGroup.
// { Pointer } dataPointer - JSON Pointer (string or array) to a data object // { FormGroup } formGroup - Angular FormGroup to get value from // { boolean = false } controlMustExist - Only return if control exists? // { Pointer } - JSON Pointer (string) to the formGroup object
Staticto'toDataPointer' function
Accepts a JSON Pointer to a sub-schema inside a JSON schema and the schema.
If possible, returns a generic Pointer to the corresponding value inside the data object described by the JSON schema.
Returns null if the sub-schema is in an ambiguous location (such as definitions or additionalProperties) where the corresponding value location cannot be determined.
// { Pointer } schemaPointer - JSON Pointer (string or array) to a JSON schema // schema - the JSON schema // { boolean = false } errors - Show errors? // { Pointer } - JSON Pointer (string) to the value in the data object
Staticto'toGenericPointer' function
Compares an indexed pointer to an array map and removes list array indexes (but leaves tuple arrray indexes and all object keys, including numeric keys) to create a generic pointer.
For example, using the indexed pointer '/foo/1/bar/2/baz/3' and the arrayMap [['/foo', 0], ['/foo/-/bar', 3], ['/foo/-/bar/-/baz', 0]] would result in the generic pointer '/foo/-/bar/2/baz/-' Using the indexed pointer '/foo/1/bar/4/baz/3' and the same arrayMap would result in the generic pointer '/foo/-/bar/-/baz/-' (the bar array has 3 tuple items, so index 2 is retained, but 4 is removed)
The structure of the arrayMap is: [['path to array', number of tuple items]...]
// { Pointer } indexedPointer - The indexed pointer (array or string) // { Map<string, number> } arrayMap - The optional array map (for preserving tuple indexes) // { string } - The generic pointer with indexes removed
Staticto'toIndexedPointer' function
Merges an array of numeric indexes and a generic pointer to create an indexed pointer for a specific item.
For example, merging the generic pointer '/foo/-/bar/-/baz' and the array [4, 2] would result in the indexed pointer '/foo/4/bar/2/baz'
// { Pointer } genericPointer - The generic pointer // { number[] } indexArray - The array of numeric indexes // { Map<string, number> } arrayMap - An optional array map // { string } - The merged pointer with indexes
Staticto'toKey' function
Extracts name of the final key from a JSON Pointer.
// { Pointer } pointer - JSON Pointer (string or array) // { boolean = false } errors - Show error if invalid pointer? // { string } - the extracted key
Staticto'toSchemaPointer' function
Accepts a JSON Pointer to a value inside a data object and a JSON schema for that object.
Returns a Pointer to the sub-schema for the value inside the object's schema.
// { Pointer } dataPointer - JSON Pointer (string or array) to an object // schema - JSON schema for the object // { Pointer } - JSON Pointer (string) to the object's schema
Staticunescape'unescape' function
Unescapes a string reference key
// { string } key - string key to unescape // { string } - unescaped key
'compile' function
Converts an array of keys into a JSON Pointer string (if input is already a string, it is normalized and returned)
The optional second parameter is a default which will replace any empty keys.
// { Pointer } pointer - JSON Pointer (string or array) // { string | number = '' } defaultValue - Default value // { boolean = false } errors - Show error if invalid pointer? // { string } - JSON Pointer string