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
Parameter | Type | Default value | Description |
---|---|---|---|
nodes ? | Node [] | [] |
Returns
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
Returns
void
clone()
clone(
options
?):Document
Defined in: src/model/document.js:61
Create an identical copy of this document
Parameters
Parameter | Type | Description |
---|---|---|
options ? | { shallow : boolean ; } | |
options.shallow ? | boolean | If true, only clone this document and without any children |
Returns
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
Parameter | Type | Description |
---|---|---|
name | string |
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
Parameter | Type | Description |
---|---|---|
name | string |
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
Parameter | Type | Description |
---|---|---|
name | string | |
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
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
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
Parameter | Type | Description |
---|---|---|
node | Node |
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
Parameter | Type | Description |
---|---|---|
name | string |
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
Returns
void
Throws
if the oldNode is not in this document