Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nhz-io/ref-node
"Value reference node" Class
https://github.com/nhz-io/ref-node
Last synced: 4 days ago
JSON representation
"Value reference node" Class
- Host: GitHub
- URL: https://github.com/nhz-io/ref-node
- Owner: nhz-io
- License: mit
- Created: 2016-09-09T18:22:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-10T21:06:46.000Z (over 8 years ago)
- Last Synced: 2024-08-10T06:13:50.844Z (5 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
@nhz.io/ref-node
"Value reference node" Class
## Install
```
npm i -S @nhz.io/ref-node
```## Class: RefNode
### new RefNode(root, path)
* `root` - `{Array | Object}`
* `path` - `{Array}`#### 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
```javascriptconst 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
```javascript
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'
```