Licence
MIT
Version
1.0.8
Deps
0
Vulns
0
Weekly
0
@nhz.io/ref-node
"Value reference node" ClassInstall
npm i -S @nhz.io/ref-node
Class: RefNode
new RefNode(root, path)
root - {Array | Object}
path - {Array<String | Number>}
Creates a reference node for the root object at the given path.
With root: {a: {b: 'foo'}} and path: ['a', 'b'], the node will
reference 'foo' value of the a.b Object
With root; {a: b: [null, 'bar']} and path: ['a', 'b', 1], the node
will reference 'bar' value of the a.b Array at index 1
Properties
root - Root getter/setter
parent - Parent getter
path - Path getter/setter
key - Key getter/setter
resolves - Resolves getter
Example
Object key reference
const RefNode = require('@nhz.io/ref-node')
const root = {a: {b: 'foobar'}}
const node = new RefNode(root, ['a', 'b'])
console.log(node.value) // Prints 'foobar'
node.value = 'barfoo'
console.log(root.a.b) // Prints 'barfoo'
Array element reference
const RefNode = require('@nhz.io/ref-node')
const root = {a: {b: [null, 'foobar']}}
const node = new RefNode(root, ['a', 'b', 1])
console.log(node.value) // Prints 'foobar'
node.value = 'barfoo'
console.log(root.a.b[1]) // Prints 'barfoo'
Install
npm i -S @nhz.io/ref-node
Class: RefNode
new RefNode(root, path)
root-{Array | Object}path-{Array<String | Number>}
Creates a reference node for the root object at the given path.
With root:
{a: {b: 'foo'}}and path:['a', 'b'], the node will reference'foo'value of thea.bObjectWith root;
{a: b: [null, 'bar']}and path:['a', 'b', 1], the node will reference'bar'value of thea.bArray at index1
Properties
root- Root getter/setterparent- Parent getterpath- Path getter/setterkey- Key getter/setterresolves- Resolves getter
Example
Object key reference
const RefNode = require('@nhz.io/ref-node')
const root = {a: {b: 'foobar'}}
const node = new RefNode(root, ['a', 'b'])
console.log(node.value) // Prints 'foobar'
node.value = 'barfoo'
console.log(root.a.b) // Prints 'barfoo'
Array element reference
const RefNode = require('@nhz.io/ref-node')
const root = {a: {b: [null, 'foobar']}}
const node = new RefNode(root, ['a', 'b', 1])
console.log(node.value) // Prints 'foobar'
node.value = 'barfoo'
console.log(root.a.b[1]) // Prints 'barfoo'