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
Defined in
Properties
beforeChildren
beforeChildren:
undefined
|string
Whitespace between the last entry and the children
Defined in
betweenTagAndName
betweenTagAndName:
undefined
|string
Whitespace between the tag and the node name
Defined in
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
entries
entries:
Entry
[]
Entries of the node
Defined in
leading
leading:
undefined
|string
Leading whitespace
Defined in
name
name:
Identifier
The name (also known as "tag name") of this node
Defined in
tag
tag:
null
|Tag
=null
Tag attached to this value, if any
Defined in
trailing
trailing:
undefined
|string
Trailing whitespace
Defined in
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
appendNode()
appendNode(
node
):void
Add the given node at the end of this node's children
Parameters
Returns
void
Defined in
clone()
clone():
Node
Create an identical copy of this node
Returns
Defined in
deleteProperty()
deleteProperty(
name
):void
Delete the property with the given name
Parameters
• name: string
Returns
void
Defined in
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
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
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
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
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
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
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
getName()
getName():
string
Return the name of this node
Returns
string
Defined in
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
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
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
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
getTag()
getTag():
null
|string
Return the tag of this node, if any
Returns
null
| string
Defined in
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
hasArguments()
hasArguments():
boolean
Return whether this node has arguments
Returns
boolean
Defined in
hasChildren()
hasChildren():
boolean
Return whether this node has child nodes
Returns
boolean
Defined in
hasProperties()
hasProperties():
boolean
Return whether this node has properties
Returns
boolean
Defined in
hasProperty()
hasProperty(
name
):boolean
Return whether this node has the given property
Parameters
• name: string
Returns
boolean
Defined in
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
• referenceNode: null
| Node
Returns
void
Throws
If the given referenceNode is not part of this document
Defined in
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
• referenceNode: null
| Node
Returns
void
Throws
If the given referenceNode is not part of this node's children
Defined in
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
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
removeNodesByName()
removeNodesByName(
name
):void
Remove all nodes with the given name from this document
Parameters
• name: string
Returns
void
Defined in
replaceNode()
replaceNode(
oldNode
,newNode
):void
Replace the old node with the new node in this node's children
Parameters
• oldNode: Node
Returns
void
Throws
if the oldNode is not in this node's children
Defined in
setName()
setName(
name
):void
Set the name of this node to the given name
Parameters
• name: string
Returns
void
Defined in
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
setTag()
setTag(
tag
):void
Set the tag of this node to the given tag
Parameters
• tag: undefined
| null
| string
Returns
void
Defined in
create()
static
create(name
):Node
Create a new node with the given name
Parameters
• name: string