Class: Document

A document is a collection of zero or mode Nodes

Constructors

new Document()

new Document(nodes?): Document

Parameters

ParameterTypeDefault valueDescription
nodes?Node[][]

Returns

Document

Defined in

src/model/document.js:50

Properties

nodes

nodes: Node[]

The nodes in this document

Defined in

src/model/document.js:37

Methods

appendNode()

appendNode(node): void

Add the given node at the end of this document

Parameters

ParameterTypeDescription
nodeNode | Document

Returns

void

Defined in

src/model/document.js:76


clone()

clone(options?): Document

Create an identical copy of this document

Parameters

ParameterTypeDescription
options?{ shallow: boolean; }
options.shallow?booleanIf true, only clone this document and without any children

Returns

Document

Defined in

src/model/document.js:61


findNodeByName()

findNodeByName(name): undefined | Node

Return the last node in this document with the given name

This function returns the last node instead of first to be in line with how properties are defined in the KDL specification where the last property with the given name is used and the rest is shadowed.

Parameters

ParameterTypeDescription
namestring

Returns

undefined | Node

Defined in

src/model/document.js:176


findNodesByName()

findNodesByName(name): Node[]

Return all nodes with the given node name

Changes to the returned array are not reflected back onto this document itself, and updates to the document won't reflect in the returned array.

Parameters

ParameterTypeDescription
namestring

Returns

Node[]

Defined in

src/model/document.js:162


findParameterizedNode()

findParameterizedNode(name, parameter?): undefined | Node

Return the last node in this document with the given name, matching the parameter

If the parameter is undefined, this method looks for a node with any single arguments. If a parameter is passed, this method looks for a node with a single parameter, equal to the given parameter.

Parameters

ParameterTypeDescription
namestring
parameter?Primitive

Returns

undefined | Node

Defined in

src/model/document.js:197


insertNodeAfter()

insertNodeAfter(newNode, referenceNode): void

Insert the given node to the document after the referenceNode, or at the beginning if no reference is passed

Parameters

ParameterTypeDescription
newNodeNode | Document
referenceNodenull | Node

Returns

void

Throws

If the given referenceNode is not part of this document

Defined in

src/model/document.js:108


insertNodeBefore()

insertNodeBefore(newNode, referenceNode): void

Insert the given node to the document before the referenceNode, or at the end if no reference is passed

Parameters

ParameterTypeDescription
newNodeNode | Document
referenceNodenull | Node

Returns

void

Throws

If the given referenceNode is not part of this document

Defined in

src/model/document.js:87


isEmpty()

isEmpty(): boolean

Return whether the document is empty

Returns

boolean

Defined in

src/model/document.js:232


removeNode()

removeNode(node): void

Remove the given node from this document

Parameters

ParameterTypeDescription
nodeNode

Returns

void

Throws

if the given node is not in this document

Defined in

src/model/document.js:128


removeNodesByName()

removeNodesByName(name): void

Remove all nodes with the given name from this document

Parameters

ParameterTypeDescription
namestring

Returns

void

Defined in

src/model/document.js:223


replaceNode()

replaceNode(oldNode, newNode): void

Replace the old node with the new node in this document

Parameters

ParameterTypeDescription
oldNodeNode
newNodeNode | Document

Returns

void

Throws

if the oldNode is not in this document

Defined in

src/model/document.js:144