1.0.3 • Published 3 years ago
gluenode v1.0.3
Glue Node 
A DOM-like data structure
Get Started
npm install gluenode --saveExample
Node relationship diagram

import { createNode } from 'gluenode';
const windy = createNode({
name: 'Windy',
age: 20,
});
windy.get('age'); // Output: 20
windy.get('name'); // Output: "Windy"
const diluc = createNode({
name: 'Diluc',
age: 28,
});
const klee = createNode({
name: 'Klee',
age: 8,
});
const barbara = createNode({
name: 'Barbara',
age: 12,
});
const bennett = createNode({
name: 'Bennett',
age: 13,
});
const jean = createNode({
name: 'Jean',
age: 23,
});
windy.appendChild(diluc)
.appendChild(klee)
.appendChild(barbara);
barbara.appendChild(bennett)
.appendChild(jean);
diluc.previousSibling; // Output: null
diluc.nextSibling; // Output: klee(GlueNode<{ name: string; age: number; }>)
klee.parentNode; // Output: windy(GlueNode<{ name: string; age: number; }>)
Array.from(barbara.children); // Output: [bennett, jean]
barbara.firstChild; // Output: bennett
barbara.lastChild; // Output: jeanAPI
Constructor
new (original: T): GlueNode<T>GlueNode.create(original: T): GlueNode<T>
Properties
originGet original objectparentNodeGet parent nodepreviousSiblingGet previous siblingnextSiblingGet next siblingfirstChildGet first childlastChildGet last childfirstSiblingGet first siblinglastSiblingGet last siblingrootNodeGet root nodesourceChainGet chain
Array.from(glueNode.sourceChain) // [this, father, grandfather, ..., root]
// or
glueNode.sourceChain.toArray()childrenGet children { Symbol.iterator }
// transform glueNode.children to Array
Array.from(glueNode.children)
// or
glueNode.children.toArray()siblingsGet all siblings
Array.from(glueNode.siblings) // [firstSibling, ... , previousSibling, this, nextSibling, ..., lastSibling]
// or
glueNode.siblings.toArray()Methods
get<K extends keyof T>(key: K): T[K]set<K extends keyof T>(key: K, value: T[K]): thisreplaceChild(newNode: GlueNode<T>, oldNode: GlueNode<T>): thisinsertBefore(newNode: GlueNode<T>, oldNode: GlueNode<T>): thisprependChild(newNode: GlueNode<T>): thisappendChild(newNode: GlueNode<T>): thisremoveChild(node: GlueNode<T>): thisremove(): thisfind(predicate: (node: GlueNode<T>) => boolean): GlueNode<T> | nullfindChild(predicate: (node: GlueNode<T>) => boolean): GlueNode<T> | nullfindSibling(predicate: (node: GlueNode<T>) => boolean): GlueNode<T> | nulltoJSON(): T & { children: T[] }