You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

key-nodes

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-nodes

Tree nodes for key and key/value pairs in object path hierarchies.

2.0.2
latest
Source
npmnpm
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Key Nodes

Tree nodes for key and key/value pairs in object path hierarchies.

KeyNode

Tree node for keys.

Example:

import {KeyNode} from 'key-nodes';

// Start with root key node.
const foo = new KeyNode('foo');

console.log(foo.key); // "foo"

// Add sibling root key node
const bar = foo.addSibling('bar');

console.log(foo.hasSibling('bar')); // true
console.log(bar.hasSibling('foo')); // true

// Add child key node
const baz = foo.addChild('baz');

console.log(foo.hasChild('baz')); // true

// Add child to baz key node
const qux = baz.addChild('qux');

console.log(baz.hasChild('qux')); // true

// Add indexes
const arr0 = qux.addChild(0);

console.log(arr0.keyType); // "index"
console.log(qux.keyType); // "key"

KeyValueNode

Tree node for key/value pairs.

Example:

import {KeyValueNode} from 'key-nodes';

// Start with root key/value node.
const foo = new KeyValueNode('foo');

console.log(foo.key); // "foo"

// Add sibling root key/value node with value.
const bar = foo.addSibling('bar', 11);

console.log(foo.hasSibling('bar')); // true
console.log(bar.hasSibling('foo')); // true

console.log(bar.value); // 11

// Track value history up to 2 changes
bar.keepHistory = 2;

// Change bar value
bar.value = 13;

console.log(bar.value); // 13

// Undo value change
bar.undo();

console.log(bar.value); // 11

// Redo value change
bar.redo();

console.log(bar.value); // 13

// Stop tracking history
bar.keepHistory = false;
bar.value = 17;

console.log(bar.value); // 17
console.log( bar.undo() ); // false
console.log(bar.value); // 17

// Add child key/value node
const baz = foo.addChild('baz');

console.log(foo.hasChild('baz')); // true

// Add indexes with values
const arr0 = baz.addChild(0, 'Value at index 0');
const arr1 = baz.addChild(1, 'Value at index 1');


console.log(arr0.value); // "Value at index 0"
console.log(arr1.value); // "Value at index 1"

console.log(arr1.keyType); // "index"
console.log(baz.keyType); // "key"

Full docs.

FAQs

Package last updated on 14 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.