1.1.9 • Published 3 years ago

reftools v1.1.9

Weekly downloads
277,935
License
BSD-3-Clause
Repository
github
Last release
3 years ago

RefTools

Functions

Typedefs

nop(obj) ⇒

a no-op placeholder which returns the given object unchanged useful for when a clone function needs to be passed but cloning is not required

Kind: global function
Returns: the input object, unchanged

ParamDescription
objthe input object

clone(obj) ⇒

clones the given object using JSON.parse and JSON.stringify

Kind: global function
Returns: the cloned object

ParamDescription
objthe object to clone

shallowClone(obj) ⇒

clones the given object's properties shallowly, ignores properties from prototype

Kind: global function
Returns: the cloned object

ParamDescription
objthe object to clone

deepClone(obj) ⇒

clones the given object's properties deeply, ignores properties from prototype

Kind: global function
Returns: the cloned object

ParamDescription
objthe object to clone

fastClone(obj) ⇒

clones the given object's properties shallowly, using Object.assign

Kind: global function
Returns: the cloned object

ParamDescription
objthe object to clone

circularClone()

Source: stackoverflow http://bit.ly/2A1Kha6

Kind: global function

dereference(o) ⇒

dereferences the given object

Kind: global function
Returns: the dereferenced object
Definitions: a source of definitions to reference
Options: optional settings (used recursively)

ParamDescription
othe object to dereference

flatten(obj, callback) ⇒

flattens an object into an array of properties

Kind: global function
Returns: the flattened object as an array of properties

ParamDescription
objthe object to flatten
callbacka function which can mutate or filter the entries (by returning null)

jpescape(s) ⇒

escapes JSON Pointer using ~0 for ~ and ~1 for /

Kind: global function
Returns: the escaped string

ParamDescription
sthe string to escape

jpunescape(s) ⇒

unescapes JSON Pointer using ~0 for ~ and ~1 for /

Kind: global function
Returns: the unescaped string

ParamDescription
sthe string to unescape

jptr(obj, prop, newValue) ⇒

from obj, return the property with a JSON Pointer prop, optionally setting it to newValue

Kind: global function
Returns: the found property, or false

ParamDescription
objthe object to point into
propthe JSON Pointer or JSON Reference
newValueoptional value to set the property to

recurse(object, state, callback)

recurses through the properties of an object, given an optional starting state anything you pass in state.payload is passed to the callback each time

Kind: global function

ParamDescription
objectthe object to recurse through
stateoptional starting state, can be set to null or
callbackthe function which receives object,key,state on each property

reref(obj, options) ⇒

Simply modifies an object to have no self-references by replacing them with $ref pointers

Kind: global function
Returns: the re-referenced object (mutated)

ParamDescription
objthe object to re-reference
optionsmay contain a prefix property for the generated refs

objToGraph(obj, containerName) ⇒

Takes an object and creates a graph of JSON Pointer / References

Kind: global function
Returns: the graph suitable for passing to toposort()

ParamDescription
objthe object to convert
containerNamethe property containing definitions. Default: definitions

visit(obj, comparison, callbacks) ⇒

Given an expanded object and an optional object to compare to (e.g. its $ref'd form), will call the following functions:

  • callbacks.before - lets you modify the initial starting state, must return it
  • callbacks.where - lets you select a subset of properties, return a truthy value
  • callbacks.filter - called for all selected properties, can mutate/remove (by setting to undefined)
  • callbacks.compare - allowing the objects to be compared by path (i.e. for $ref reinstating)
  • callbacks.identity - called on any object identity (previously seen) properties
  • callbacks.selected - called for all selected/unfiltered properties, does not mutate directly
  • callbacks.count - called at the end with the number of selected properties
  • callbacks.finally - called at the end of the traversal

Kind: global function
Returns: the possibly mutated object

ParamDescription
objthe object to visit
comparisonoptional object to compare to
callbacksobject containing functions as above

Result ⇒ Result

Try to get a topological sorting out of directed graph.

Kind: global typedef

ParamTypeDescription
nodesObjectA list of nodes, including edges (see below).

Properties

NameTypeDescription
sortarraythe sort, empty if not found
nodesWithEdges,arraywill be empty unless a cycle is found
1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago