Class: Node

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

Parameters

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

Returns

Node

Defined in

src/model/node.js:109

Properties

children

children: null | Document

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.

Defined in

src/model/node.js:70


entries

entries: Entry[]

Entries of the node

Defined in

src/model/node.js:60


name

name: Identifier

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

Defined in

src/model/node.js:46


tag

tag: null | Tag = null

Tag attached to this node, if any

Defined in

src/model/node.js:53

Methods

addArgument()

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

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

Defined in

src/model/node.js:277


appendNode()

appendNode(node): void

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

Parameters

ParameterTypeDescription
nodeNode | Document

Returns

void

Defined in

src/model/node.js:464


clone()

clone(options?): Node

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

Defined in

src/model/node.js:122


deleteProperty()

deleteProperty(name): void

Delete the property with the given name

Parameters

ParameterTypeDescription
namestring

Returns

void

Defined in

src/model/node.js:446


findNodeByName()

findNodeByName(name): undefined | Node

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

Defined in

src/model/node.js:542


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


findParameterizedNode()

findParameterizedNode(name, parameter?): undefined | Node

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

Defined in

src/model/node.js:557


getArgument()

getArgument(index): undefined | Primitive

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

Defined in

src/model/node.js:235


getArgumentEntries()

getArgumentEntries(): Entry[]

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

Defined in

src/model/node.js:205


getArgumentEntry()

getArgumentEntry(index): undefined | Entry

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

Defined in

src/model/node.js:250


getArguments()

getArguments(): Primitive[]

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

Defined in

src/model/node.js:193


getName()

getName(): string

Return the name of this node

Returns

string

Defined in

src/model/node.js:163


getProperties()

getProperties(): Map<string, Primitive>

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>

Defined in

src/model/node.js:341


getProperty()

getProperty(name): undefined | Primitive

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

Parameters

ParameterTypeDescription
namestring

Returns

undefined | Primitive

Defined in

src/model/node.js:396


getPropertyEntries()

getPropertyEntries(): Entry[]

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

Defined in

src/model/node.js:358


getPropertyEntry()

getPropertyEntry(name): undefined | Entry

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

Parameters

ParameterTypeDescription
namestring

Returns

undefined | Entry

Defined in

src/model/node.js:407


getPropertyEntryMap()

getPropertyEntryMap(): Map<string, Entry>

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>

Defined in

src/model/node.js:370


getTag()

getTag(): null | string

Return the tag of this node, if any

Returns

null | string

Defined in

src/model/node.js:145


hasArgument()

hasArgument(index): boolean

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

Defined in

src/model/node.js:220


hasArguments()

hasArguments(): boolean

Return whether this node has arguments

Returns

boolean

Defined in

src/model/node.js:181


hasChildren()

hasChildren(): boolean

Return whether this node has child nodes

Returns

boolean

Defined in

src/model/node.js:455


hasProperties()

hasProperties(): boolean

Return whether this node has properties

Returns

boolean

Defined in

src/model/node.js:329


hasProperty()

hasProperty(name): boolean

Return whether this node has the given property

Parameters

ParameterTypeDescription
namestring

Returns

boolean

Defined in

src/model/node.js:385


insertNodeAfter()

insertNodeAfter(newNode, referenceNode): void

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

Defined in

src/model/node.js:486


insertNodeBefore()

insertNodeBefore(newNode, referenceNode): void

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

Defined in

src/model/node.js:475


removeArgument()

removeArgument(index): void

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

Defined in

src/model/node.js:309


removeNode()

removeNode(node): void

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

Defined in

src/model/node.js:496


removeNodesByName()

removeNodesByName(name): void

Remove all nodes with the given name from this document

Parameters

ParameterTypeDescription
namestring

Returns

void

Defined in

src/model/node.js:567


replaceNode()

replaceNode(oldNode, newNode): void

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

Defined in

src/model/node.js:511


setName()

setName(name): void

Set the name of this node to the given name

Parameters

ParameterTypeDescription
namestring

Returns

void

Defined in

src/model/node.js:172


setProperty()

setProperty(name, value, tag?): void

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

Defined in

src/model/node.js:427


setTag()

setTag(tag): void

Set the tag of this node to the given tag

Parameters

ParameterTypeDescription
tagundefined | null | string

Returns

void

Defined in

src/model/node.js:154


create()

static create(name): Node

Create a new node with the given name

Parameters

ParameterTypeDescription
namestring

Returns

Node

Defined in

src/model/node.js:25