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
Parameter | Type | Default value | Description |
---|---|---|---|
name | Identifier | undefined | |
entries ? | Entry [] | [] | |
children ? | null | Document | null |
Returns
Defined in
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
entries
entries:
Entry
[]
Entries of the node
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 node, if any
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
Parameter | Type | Description |
---|---|---|
value | Primitive | 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(
options
?):Node
Create an identical copy of this node
Parameters
Parameter | Type | Description |
---|---|---|
options ? | { shallow : boolean ; } | |
options.shallow ? | boolean | If true, only copy this node but don't clone this node's children. |
Returns
Defined in
deleteProperty()
deleteProperty(
name
):void
Delete the property with the given name
Parameters
Parameter | Type | Description |
---|---|---|
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
Parameter | Type | Description |
---|---|---|
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
Parameter | Type | Description |
---|---|---|
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
Parameter | Type | Description |
---|---|---|
name | string | |
parameter ? | Primitive |
Returns
undefined
| Node
Defined in
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
Parameter | Type | Description |
---|---|---|
index | number |
Returns
undefined
| Primitive
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
Parameter | Type | Description |
---|---|---|
index | number |
Returns
undefined
| Entry
Defined in
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
Defined in
getName()
getName():
string
Return the name of this node
Returns
string
Defined in
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
getProperty()
getProperty(
name
):undefined
|Primitive
Return the value of the property with the given name, or undefined if it doesn't exist.
Parameters
Parameter | Type | Description |
---|---|---|
name | string |
Returns
undefined
| Primitive
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
Parameter | Type | Description |
---|---|---|
name | string |
Returns
undefined
| Entry
Defined in
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
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
Parameter | Type | Description |
---|---|---|
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
Parameter | Type | Description |
---|---|---|
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
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
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
Parameter | Type | Description |
---|---|---|
index | number |
Returns
void
Defined in
removeNode()
removeNode(
node
):void
Remove the given node from this node's children
Parameters
Parameter | Type | Description |
---|---|---|
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
Parameter | Type | Description |
---|---|---|
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
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
Parameter | Type | Description |
---|---|---|
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
Parameter | Type | Description |
---|---|---|
name | string | |
value | Primitive | |
tag ? | null | string |
Returns
void
Defined in
setTag()
setTag(
tag
):void
Set the tag of this node to the given tag
Parameters
Parameter | Type | Description |
---|---|---|
tag | undefined | null | string |
Returns
void
Defined in
create()
static
create(name
):Node
Create a new node with the given name
Parameters
Parameter | Type | Description |
---|---|---|
name | string |