Gathering detailed insights and metrics for symbol-tree2
Gathering detailed insights and metrics for symbol-tree2
Gathering detailed insights and metrics for symbol-tree2
Gathering detailed insights and metrics for symbol-tree2
Turn any collection of objects into its own efficient tree or linked list using Symbol
npm install symbol-tree2
Typescript
Module System
Node Version
NPM Version
JavaScript (70.82%)
TypeScript (29.18%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
97 Commits
2 Watchers
4 Branches
1 Contributors
Updated on Apr 01, 2018
Latest Version
3.2.3
Package Id
symbol-tree2@3.2.3
Unpacked Size
90.61 kB
Size
12.24 kB
File Count
16
NPM Version
5.6.0
Node Version
9.10.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Turn any collection of objects into its own efficient tree or linked list using Symbol
.
This library has been designed to provide an efficient backing data structure for DOM trees. You can also use this library as an efficient linked list. Any meta data is stored on your objects directly, which ensures any kind of insertion or deletion is performed in constant time. Because an ES6 Symbol
is used, the meta data does not interfere with your object in any way.
Node.js 4+, io.js and modern browsers are supported.
A linked list:
1const SymbolTree = require('symbol-tree'); 2const tree = new SymbolTree(); 3 4let a = {foo: 'bar'}; // or `new Whatever()` 5let b = {foo: 'baz'}; 6let c = {foo: 'qux'}; 7 8tree.insertBefore(b, a); // insert a before b 9tree.insertAfter(b, c); // insert c after b 10 11console.log(tree.nextSibling(a) === b); 12console.log(tree.nextSibling(b) === c); 13console.log(tree.previousSibling(c) === b); 14 15tree.remove(b); 16console.log(tree.nextSibling(a) === c);
A tree:
1const SymbolTree = require('symbol-tree'); 2const tree = new SymbolTree(); 3 4let parent = {}; 5let a = {}; 6let b = {}; 7let c = {}; 8 9tree.prependChild(parent, a); // insert a as the first child 10tree.appendChild(parent,c ); // insert c as the last child 11tree.insertAfter(a, b); // insert b after a, it now has the same parent as a 12 13console.log(tree.firstChild(parent) === a); 14console.log(tree.nextSibling(tree.firstChild(parent)) === b); 15console.log(tree.lastChild(parent) === c); 16 17let grandparent = {}; 18tree.prependChild(grandparent, parent); 19console.log(tree.firstChild(tree.firstChild(grandparent)) === a);
Make sure you install the dependencies first:
npm install
You can now run the unit tests by executing:
npm test
The line and branch coverage should be 100%.
Author: Joris van der Wel joris@jorisvanderwel.com
Object
Boolean
Object
Object
Object
Object
Object
Object
Object
Object
Array.<Object>
Array.<Object>
Array.<Object>
Object
Object
Object
Object
Object
Number
Number
Number
Object
Object
Object
Object
Object
Param | Type | Default | Description |
---|---|---|---|
[description] | string | "'SymbolTree data'" | Description used for the Symbol |
Object
You can use this function to (optionally) initialize an object right after its creation, to take advantage of V8's fast properties. Also useful if you would like to freeze your object.
O(1)
Kind: instance method of SymbolTree
Returns: Object
- object
Param | Type |
---|---|
object | Object |
Boolean
Returns true
if the object has any children. Otherwise it returns false
.
O(1)
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Returns the first child of the given object.
O(1)
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Returns the last child of the given object.
O(1)
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Returns the previous sibling of the given object.
O(1)
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Returns the next sibling of the given object.
O(1)
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Return the parent of the given object.
O(1)
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Find the inclusive descendant that is last in tree order of the given object.
O(n)
(worst case) where n
is the depth of the subtree of object
Kind: instance method of SymbolTree
Param | Type |
---|---|
object | Object |
Object
Find the preceding object (A) of the given object (B). An object A is preceding an object B if A and B are in the same tree and A comes before B in tree order.
O(n)
(worst case)O(1)
(amortized when walking the entire tree)Kind: instance method of SymbolTree
Param | Type | Description |
---|---|---|
object | Object | |
[options] | Object | |
[options.root] | Object | If set, root must be an inclusive ancestor of the return value (or else null is returned). This check assumes that root is also an inclusive ancestor of the given object |
Object
Find the following object (A) of the given object (B). An object A is following an object B if A and B are in the same tree and A comes after B in tree order.
O(n)
(worst case) where n
is the amount of objects in the entire treeO(1)
(amortized when walking the entire tree)Kind: instance method of SymbolTree
Param | Type | Default | Description |
---|---|---|---|
object | Object | ||
[options] | Object | ||
[options.root] | Object | If set, root must be an inclusive ancestor of the return value (or else null is returned). This check assumes that root is also an inclusive ancestor of the given object | |
[options.skipChildren] | Boolean | false | If set, ignore the children of object |
Array.<Object>
Append all children of the given object to an array.
O(n)
where n
is the amount of children of the given parent
Kind: instance method of SymbolTree
Param | Type | Default | Description |
---|---|---|---|
parent | Object | ||
[options] | Object | ||
[options.array] | Array.<Object> | [] | |
[options.filter] | function | Function to test each object before it is added to the array. Invoked with arguments (object). Should return true if an object is to be included. | |
[options.thisArg] | * | Value to use as this when executing filter . |
Array.<Object>
Append all inclusive ancestors of the given object to an array.
O(n)
where n
is the amount of ancestors of the given object
Kind: instance method of SymbolTree
Param | Type | Default | Description |
---|---|---|---|
object | Object | ||
[options] | Object | ||
[options.array] | Array.<Object> | [] | |
[options.filter] | function | Function to test each object before it is added to the array. Invoked with arguments (object). Should return true if an object is to be included. | |
[options.thisArg] | * | Value to use as this when executing filter . |
Array.<Object>
Append all descendants of the given object to an array (in tree order).
O(n)
where n
is the amount of objects in the sub-tree of the given object
Kind: instance method of SymbolTree
Param | Type | Default | Description |
---|---|---|---|
root | Object | ||
[options] | Object | ||
[options.array] | Array.<Object> | [] | |
[options.filter] | function | Function to test each object before it is added to the array. Invoked with arguments (object). Should return true if an object is to be included. | |
[options.thisArg] | * | Value to use as this when executing filter . |
Object
Iterate over all children of the given object
O(1)
for a single iterationKind: instance method of SymbolTree
Returns: Object
- An iterable iterator (ES6)
Param | Type | Default |
---|---|---|
parent | Object | |
[options] | Object | |
[options.reverse] | Boolean | false |
Object
Iterate over all the previous siblings of the given object. (in reverse tree order)
O(1)
for a single iterationKind: instance method of SymbolTree
Returns: Object
- An iterable iterator (ES6)
Param | Type |
---|---|
object | Object |
Object
Iterate over all the next siblings of the given object. (in tree order)
O(1)
for a single iterationKind: instance method of SymbolTree
Returns: Object
- An iterable iterator (ES6)
Param | Type |
---|---|
object | Object |
Object
Iterate over all inclusive ancestors of the given object
O(1)
for a single iterationKind: instance method of SymbolTree
Returns: Object
- An iterable iterator (ES6)
Param | Type |
---|---|
object | Object |
Object
Iterate over all descendants of the given object (in tree order).
Where n
is the amount of objects in the sub-tree of the given root
:
O(n)
(worst case for a single iteration)O(n)
(amortized, when completing the iterator)Kind: instance method of SymbolTree
Returns: Object
- An iterable iterator (ES6)
Param | Type | Default |
---|---|---|
root | Object | |
options | Object | |
[options.reverse] | Boolean | false |
Number
Find the index of the given object (the number of preceding siblings).
O(n)
where n
is the amount of preceding siblingsO(1)
(amortized, if the tree is not modified)Kind: instance method of SymbolTree
Returns: Number
- The number of preceding siblings, or -1 if the object has no parent
Param | Type |
---|---|
child | Object |
Number
Calculate the number of children.
O(n)
where n
is the amount of childrenO(1)
(amortized, if the tree is not modified)Kind: instance method of SymbolTree
Param | Type |
---|---|
parent | Object |
Number
Compare the position of an object relative to another object. A bit set is returned:
The semantics are the same as compareDocumentPosition in DOM, with the exception that DISCONNECTED never occurs with any other bit.
where n
and m
are the amount of ancestors of left
and right
;
where o
is the amount of children of the lowest common ancestor of left
and right
:
O(n + m + o)
(worst case)O(n + m)
(amortized, if the tree is not modified)Kind: instance method of SymbolTree
Param | Type |
---|---|
left | Object |
right | Object |
Object
Remove the object from this tree. Has no effect if already removed.
O(1)
Kind: instance method of SymbolTree
Returns: Object
- removeObject
Param | Type |
---|---|
removeObject | Object |
Object
Insert the given object before the reference object.
newObject
is now the previous sibling of referenceObject
.
O(1)
Kind: instance method of SymbolTree
Returns: Object
- newObject
Throws:
Error
If the newObject is already present in this SymbolTreeParam | Type |
---|---|
referenceObject | Object |
newObject | Object |
Object
Insert the given object after the reference object.
newObject
is now the next sibling of referenceObject
.
O(1)
Kind: instance method of SymbolTree
Returns: Object
- newObject
Throws:
Error
If the newObject is already present in this SymbolTreeParam | Type |
---|---|
referenceObject | Object |
newObject | Object |
Object
Insert the given object as the first child of the given reference object.
newObject
is now the first child of referenceObject
.
O(1)
Kind: instance method of SymbolTree
Returns: Object
- newObject
Throws:
Error
If the newObject is already present in this SymbolTreeParam | Type |
---|---|
referenceObject | Object |
newObject | Object |
Object
Insert the given object as the last child of the given reference object.
newObject
is now the last child of referenceObject
.
O(1)
Kind: instance method of SymbolTree
Returns: Object
- newObject
Throws:
Error
If the newObject is already present in this SymbolTreeParam | Type |
---|---|
referenceObject | Object |
newObject | Object |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More