Class: Document

Defined in: src/model/document.js:19

A document is a collection of zero or mode Nodes

Constructors

new Document()

new Document(nodes?): Document

Defined in: src/model/document.js:50

Parameters

ParameterTypeDefault valueDescription
nodes?Node[][]

Returns

Document

Properties

nodes

nodes: Node[]

Defined in: src/model/document.js:37

The nodes in this document

Methods

appendNode()

appendNode(node): void

Defined in: src/model/document.js:76

Add the given node at the end of this document

Parameters

ParameterTypeDescription
nodeNode | Document

Returns

void


clone()

clone(options?): Document

Defined in: src/model/document.js:61

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


findNodeByName()

findNodeByName(name): undefined | Node

Defined in: src/model/document.js:176

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


findNodesByName()

findNodesByName(name): Node[]

Defined in: src/model/document.js:162

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[]


findParameterizedNode()

findParameterizedNode(name, parameter?): undefined | Node

Defined in: src/model/document.js:197

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


insertNodeAfter()

insertNodeAfter(newNode, referenceNode): void

Defined in: src/model/document.js:108

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


insertNodeBefore()

insertNodeBefore(newNode, referenceNode): void

Defined in: src/model/document.js:87

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


isEmpty()

isEmpty(): boolean

Defined in: src/model/document.js:232

Return whether the document is empty

Returns

boolean


removeNode()

removeNode(node): void

Defined in: src/model/document.js:128

Remove the given node from this document

Parameters

ParameterTypeDescription
nodeNode

Returns

void

Throws

if the given node is not in this document


removeNodesByName()

removeNodesByName(name): void

Defined in: src/model/document.js:223

Remove all nodes with the given name from this document

Parameters

ParameterTypeDescription
namestring

Returns

void


replaceNode()

replaceNode(oldNode, newNode): void

Defined in: src/model/document.js:144

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