Home Reference Source

Function

Static Public Summary
public

contains(object: Object, key: String): Boolean

A simple function to safely check if an object has a given property

public

dereference(schema: Array | Object, resolve: Object): Object

This function dereferences a schema set into one logical schema in accordance with the IETF JSON Reference Draft v3 specification:

public

iterate(object: Object, fn: Function)

A method to safely iterate the properties of an object and execute some function for each of them.

public

map(object: Object, fn: Function): Object

An object literal variant of the Array.map function.

public

merge(object: Object, object: Object, overide: Boolean): Object

A function to allowing deep merging of object literals using various strategies.

Static Public

public contains(object: Object, key: String): Boolean source

import {contains} from '@jdw/jst/src/object.js'

A simple function to safely check if an object has a given property

Params:

NameTypeAttributeDescription
object Object

An object literal to iterate over.

key String

The property to check the object for.

Return:

Boolean

The boolean result of the check.

public dereference(schema: Array | Object, resolve: Object): Object source

import dereference from '@jdw/jst/src/dereference.js'

This function dereferences a schema set into one logical schema in accordance with the IETF JSON Reference Draft v3 specification:

https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03

It allows for one to inject a schema resolution function in order to provide it with referenced schema. This allows developers to be flexible in choosing there schema sources such as HTTP or in-memory resolvers.

The dereference function also resolves JSON Pointers according to the IETF RFC6901 specification:

https://tools.ietf.org/html/rfc6901

It does so internaly rather than through an external resolver in order to remain efficient.

Params:

NameTypeAttributeDescription
schema Array | Object

A schema or array of schema to dereference.

resolve Object

A function to resolve referenced schema by its id.

Return:

Object

The dereferenced schema as an object.

public iterate(object: Object, fn: Function) source

import {iterate} from '@jdw/jst/src/object.js'

A method to safely iterate the properties of an object and execute some function for each of them.

Params:

NameTypeAttributeDescription
object Object

An object literal to iterate over.

fn Function

A function to execute for each key in the object.

public map(object: Object, fn: Function): Object source

import {map} from '@jdw/jst/src/object.js'

An object literal variant of the Array.map function. Iterate the properties of an object applying some function to each one of them and return a new object with the results.

Params:

NameTypeAttributeDescription
object Object

An object literal to iterate over.

fn Function

A function to execute for each key in the object.

Return:

Object

A new object literal.

public merge(object: Object, object: Object, overide: Boolean): Object source

import {merge} from '@jdw/jst/src/object.js'

A function to allowing deep merging of object literals using various strategies.

Params:

NameTypeAttributeDescription
object Object

The base object we would like to merge into.

object Object

The object we would like to extend base with.

overide Boolean

Whether to override properties in base if they exist in both objecys.

Return:

Object

A new object literal.