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

name: Identifier

entries?: Entry[] = []

children?: null | Document = null

Returns

Node

Defined in

src/model/node.js:105

Properties

beforeChildren

beforeChildren: undefined | string

Whitespace between the last entry and the children

Defined in

src/model/node.js:91


betweenTagAndName

betweenTagAndName: undefined | string

Whitespace between the tag and the node name

Defined in

src/model/node.js:98


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


leading

leading: undefined | string

Leading whitespace

Defined in

src/model/node.js:77


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 value, if any

Defined in

src/model/node.js:53


trailing

trailing: undefined | string

Trailing whitespace

Defined in

src/model/node.js:84

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

value: null | string | number | boolean

The value to insert as argument

tag?: null | string

The tag to attach to the argument, if any

index?: number

The index

Returns

void

Defined in

src/model/node.js:269


appendNode()

appendNode(node): void

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

Parameters

node: Node | Document

Returns

void

Defined in

src/model/node.js:439


clone()

clone(): Node

Create an identical copy of this node

Returns

Node

Defined in

src/model/node.js:116


deleteProperty()

deleteProperty(name): void

Delete the property with the given name

Parameters

name: string

Returns

void

Defined in

src/model/node.js:421


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

name: string

Returns

undefined | Node

Defined in

src/model/node.js:517


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

name: string

Returns

Node[]

Defined in

src/model/node.js:503


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

name: string

parameter?: null | string | number | boolean

Returns

undefined | Node

Defined in

src/model/node.js:532


getArgument()

getArgument(index): undefined | null | string | number | boolean

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

index: number

Returns

undefined | null | string | number | boolean

Defined in

src/model/node.js:227


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:197


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

index: number

Returns

undefined | Entry

Defined in

src/model/node.js:242


getArguments()

getArguments(): (null | string | number | boolean)[]

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

(null | string | number | boolean)[]

Defined in

src/model/node.js:185


getName()

getName(): string

Return the name of this node

Returns

string

Defined in

src/model/node.js:155


getProperties()

getProperties(): Map<string, null | string | number | boolean>

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, null | string | number | boolean>

Defined in

src/model/node.js:333


getProperty()

getProperty(name): undefined | null | string | number | boolean

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

Parameters

name: string

Returns

undefined | null | string | number | boolean

Defined in

src/model/node.js:371


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:350


getPropertyEntry()

getPropertyEntry(name): undefined | Entry

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

Parameters

name: string

Returns

undefined | Entry

Defined in

src/model/node.js:382


getTag()

getTag(): null | string

Return the tag of this node, if any

Returns

null | string

Defined in

src/model/node.js:137


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

index: number

Returns

boolean

Defined in

src/model/node.js:212


hasArguments()

hasArguments(): boolean

Return whether this node has arguments

Returns

boolean

Defined in

src/model/node.js:173


hasChildren()

hasChildren(): boolean

Return whether this node has child nodes

Returns

boolean

Defined in

src/model/node.js:430


hasProperties()

hasProperties(): boolean

Return whether this node has properties

Returns

boolean

Defined in

src/model/node.js:321


hasProperty()

hasProperty(name): boolean

Return whether this node has the given property

Parameters

name: string

Returns

boolean

Defined in

src/model/node.js:360


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

newNode: Node | Document

referenceNode: null | Node

Returns

void

Throws

If the given referenceNode is not part of this document

Defined in

src/model/node.js:461


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

newNode: Node | Document

referenceNode: null | Node

Returns

void

Throws

If the given referenceNode is not part of this node's children

Defined in

src/model/node.js:450


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

index: number

Returns

void

Defined in

src/model/node.js:301


removeNode()

removeNode(node): void

Remove the given node from this node's children

Parameters

node: Node

Returns

void

Throws

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

Defined in

src/model/node.js:471


removeNodesByName()

removeNodesByName(name): void

Remove all nodes with the given name from this document

Parameters

name: string

Returns

void

Defined in

src/model/node.js:542


replaceNode()

replaceNode(oldNode, newNode): void

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

Parameters

oldNode: Node

newNode: Node | Document

Returns

void

Throws

if the oldNode is not in this node's children

Defined in

src/model/node.js:486


setName()

setName(name): void

Set the name of this node to the given name

Parameters

name: string

Returns

void

Defined in

src/model/node.js:164


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

name: string

value: null | string | number | boolean

tag?: null | string

Returns

void

Defined in

src/model/node.js:402


setTag()

setTag(tag): void

Set the tag of this node to the given tag

Parameters

tag: undefined | null | string

Returns

void

Defined in

src/model/node.js:146


create()

static create(name): Node

Create a new node with the given name

Parameters

name: string

Returns

Node

Defined in

src/model/node.js:25