Class: Node

Defined in: src/model/node.js:18

A node is a node name, followed by zero or more arguments and/or properties, and children

Constructors

new Node()

new Node(name, entries?, children?): Node

Defined in: src/model/node.js:109

Parameters

ParameterTypeDefault valueDescription
nameIdentifierundefined
entries?Entry[][]
children?null | Documentnull

Returns

Node

Properties

children

children: null | Document

Defined in: src/model/node.js:70

Children of the node

An empty array means the children block is present but empty, if the value is null then there is no children block.


entries

entries: Entry[]

Defined in: src/model/node.js:60

Entries of the node


name

name: Identifier

Defined in: src/model/node.js:46

The name (also known as "tag name") of this node


tag

tag: null | Tag = null

Defined in: src/model/node.js:53

Tag attached to this node, if any

Methods

addArgument()

addArgument(value, tag?, index?): void

Defined in: src/model/node.js:277

Add the given value as argument to this node

The argument is added at the given index, or at the end. This index counts towards the arguments only, i.e. if the node has five entries, three of which are arguments then inserting an argument between the second and third can be achieved by passing 2 regardless of the whether properties and arguments are interspersed or not.

Parameters

ParameterTypeDescription
valuePrimitiveThe value to insert as argument
tag?null | stringThe tag to attach to the argument, if any
index?numberThe index

Returns

void


appendNode()

appendNode(node): void

Defined in: src/model/node.js:464

Add the given node at the end of this node's children

Parameters

ParameterTypeDescription
nodeNode | Document

Returns

void


clone()

clone(options?): Node

Defined in: src/model/node.js:122

Create an identical copy of this node

Parameters

ParameterTypeDescription
options?{ shallow: boolean; }
options.shallow?booleanIf true, only copy this node but don't clone this node's children.

Returns

Node


deleteProperty()

deleteProperty(name): void

Defined in: src/model/node.js:446

Delete the property with the given name

Parameters

ParameterTypeDescription
namestring

Returns

void


findNodeByName()

findNodeByName(name): undefined | Node

Defined in: src/model/node.js:542

Return the last node in this node's children 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/node.js:528

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/node.js:557

Return the last node in this node's children 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


getArgument()

getArgument(index): undefined | Primitive

Defined in: src/model/node.js:235

Return the argument at the given index, if present

This index counts towards the arguments only, i.e. if the node has five entries, three of which are arguments then passing 1 returns the second argument, regardless of the whether properties and arguments are interspersed or not.

Parameters

ParameterTypeDescription
indexnumber

Returns

undefined | Primitive


getArgumentEntries()

getArgumentEntries(): Entry[]

Defined in: src/model/node.js:205

Return a snapshot of all arguments of this node

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

Returns

Entry[]


getArgumentEntry()

getArgumentEntry(index): undefined | Entry

Defined in: src/model/node.js:250

Return the argument entry at the given index, if present

This index counts towards the arguments only, i.e. if the node has five entries, three of which are arguments then passing 1 returns the second argument, regardless of the whether properties and arguments are interspersed or not.

Parameters

ParameterTypeDescription
indexnumber

Returns

undefined | Entry


getArguments()

getArguments(): Primitive[]

Defined in: src/model/node.js:193

Return a snapshot of all arguments of this node

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

Returns

Primitive[]


getName()

getName(): string

Defined in: src/model/node.js:163

Return the name of this node

Returns

string


getProperties()

getProperties(): Map<string, Primitive>

Defined in: src/model/node.js:341

Return a snapshot of all properties of this node

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

Returns

Map<string, Primitive>


getProperty()

getProperty(name): undefined | Primitive

Defined in: src/model/node.js:396

Return the value of the property with the given name, or undefined if it doesn't exist.

Parameters

ParameterTypeDescription
namestring

Returns

undefined | Primitive


getPropertyEntries()

getPropertyEntries(): Entry[]

Defined in: src/model/node.js:358

Return a snapshot of all properties of this node

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

Returns

Entry[]


getPropertyEntry()

getPropertyEntry(name): undefined | Entry

Defined in: src/model/node.js:407

Return the property entry with the given name, or undefined if it doesn't exist.

Parameters

ParameterTypeDescription
namestring

Returns

undefined | Entry


getPropertyEntryMap()

getPropertyEntryMap(): Map<string, Entry>

Defined in: src/model/node.js:370

Return a snapshot of all properties of this node

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

Returns

Map<string, Entry>


getTag()

getTag(): null | string

Defined in: src/model/node.js:145

Return the tag of this node, if any

Returns

null | string


hasArgument()

hasArgument(index): boolean

Defined in: src/model/node.js:220

Return the value at the given index, if present

This index counts towards the arguments only, i.e. if the node has five entries, three of which are arguments then passing 1 returns the second argument, regardless of the whether properties and arguments are interspersed or not.

Parameters

ParameterTypeDescription
indexnumber

Returns

boolean


hasArguments()

hasArguments(): boolean

Defined in: src/model/node.js:181

Return whether this node has arguments

Returns

boolean


hasChildren()

hasChildren(): boolean

Defined in: src/model/node.js:455

Return whether this node has child nodes

Returns

boolean


hasProperties()

hasProperties(): boolean

Defined in: src/model/node.js:329

Return whether this node has properties

Returns

boolean


hasProperty()

hasProperty(name): boolean

Defined in: src/model/node.js:385

Return whether this node has the given property

Parameters

ParameterTypeDescription
namestring

Returns

boolean


insertNodeAfter()

insertNodeAfter(newNode, referenceNode): void

Defined in: src/model/node.js:486

Insert the given node to the node's children 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/node.js:475

Insert the given node to the node's children 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 node's children


removeArgument()

removeArgument(index): void

Defined in: src/model/node.js:309

Remove the argument at the given index

The index counts towards the arguments only, i.e. if the node has five entries, three of which are arguments then the last argument can be removed by passing 2, regardless of whether the third argument is also the third entry.

Parameters

ParameterTypeDescription
indexnumber

Returns

void


removeNode()

removeNode(node): void

Defined in: src/model/node.js:496

Remove the given node from this node's children

Parameters

ParameterTypeDescription
nodeNode

Returns

void

Throws

if the given node is not in this node's children


removeNodesByName()

removeNodesByName(name): void

Defined in: src/model/node.js:567

Remove all nodes with the given name from this document

Parameters

ParameterTypeDescription
namestring

Returns

void


replaceNode()

replaceNode(oldNode, newNode): void

Defined in: src/model/node.js:511

Replace the old node with the new node in this node's children

Parameters

ParameterTypeDescription
oldNodeNode
newNodeNode | Document

Returns

void

Throws

if the oldNode is not in this node's children


setName()

setName(name): void

Defined in: src/model/node.js:172

Set the name of this node to the given name

Parameters

ParameterTypeDescription
namestring

Returns

void


setProperty()

setProperty(name, value, tag?): void

Defined in: src/model/node.js:427

Set the given property on this node

This function updates the property entry with the given name, if it exists.

Parameters

ParameterTypeDescription
namestring
valuePrimitive
tag?null | string

Returns

void


setTag()

setTag(tag): void

Defined in: src/model/node.js:154

Set the tag of this node to the given tag

Parameters

ParameterTypeDescription
tagundefined | null | string

Returns

void


create()

static create(name): Node

Defined in: src/model/node.js:25

Create a new node with the given name

Parameters

ParameterTypeDescription
namestring

Returns

Node