Class: Document

index.Document

A document is a collection of zero or mode Nodes

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Document(nodes?): Document

Parameters

NameTypeDefault value
nodes?Node[][]

Returns

Document

Defined in

src/model/document.js:49

Properties

nodes

nodes: Node[]

The nodes in this document

Defined in

src/model/document.js:37


trailing

trailing: undefined | string

Trailing whitespace

Defined in

src/model/document.js:44

Methods

appendNode

appendNode(node): void

Add the given node at the end of this document

Parameters

NameType
nodeNode | Document

Returns

void

Defined in

src/model/document.js:71


clone

clone(): Document

Create an identical copy of this document

Returns

Document

Defined in

src/model/document.js:58


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

NameType
namestring

Returns

undefined | Node

Defined in

src/model/document.js:171


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

NameType
namestring

Returns

Node[]

Defined in

src/model/document.js:157


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

NameType
namestring
parameter?null | string | number | boolean

Returns

undefined | Node

Defined in

src/model/document.js:192


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

NameType
newNodeNode | Document
referenceNodenull | Node

Returns

void

Throws

If the given referenceNode is not part of this document

Defined in

src/model/document.js:103


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

NameType
newNodeNode | Document
referenceNodenull | Node

Returns

void

Throws

If the given referenceNode is not part of this document

Defined in

src/model/document.js:82


isEmpty

isEmpty(): boolean

Return whether the document is empty

Returns

boolean

Defined in

src/model/document.js:227


removeNode

removeNode(node): void

Remove the given node from this document

Parameters

NameType
nodeNode

Returns

void

Throws

if the given node is not in this document

Defined in

src/model/document.js:123


removeNodesByName

removeNodesByName(name): void

Remove all nodes with the given name from this document

Parameters

NameType
namestring

Returns

void

Defined in

src/model/document.js:218


replaceNode

replaceNode(oldNode, newNode): void

Replace the old node with the new node in this document

Parameters

NameType
oldNodeNode
newNodeNode | Document

Returns

void

Throws

if the oldNode is not in this document

Defined in

src/model/document.js:139