Class: Node<T>
hierarchy.Node
Base class for implementing typed hierarchies with helpers for iterating and finding elements.
Type parameters
Name | Type |
---|---|
T |
extends Node <T > |
Constructors
constructor
• new Node<T
>(name
, children?
): Node
<T
>
Type parameters
Name | Type |
---|---|
T |
extends Node <T > |
Parameters
Name | Type |
---|---|
name |
string |
children? |
T [] |
Returns
Node
<T
>
Properties
children
• Optional
children: T
[]
name
• name: string
Methods
getNode
▸ getNode(this
, matcher
): undefined
| T
Returns the first node from the hierarchy, including this one, that matches the filtering options.
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
matcher |
Matcher <T > |
Filtering options |
Returns
undefined
| T
▸ getNode(this
, filter
): undefined
| T
Returns the first node from the hierarchy, including this one, whose name matches the provided filter.
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
filter |
Filter |
String or RegExp for filtering the nodes |
Returns
undefined
| T
▸ getNode<T2
>(this
, type
): undefined
| T2
Returns the first node from the hierarchy, including this one, whose type matches the provided type.
Type parameters
Name | Type |
---|---|
T2 |
extends Node <T > |
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
type |
Type <T2 > |
Type for filtering the nodes |
Returns
undefined
| T2
▸ getNode<T2
>(this
, type
, filter
): undefined
| T2
Returns the first node from the hierarchy, including this one, whose type matches the provided type and name matches the provided filter.
Type parameters
Name | Type |
---|---|
T2 |
extends Node <T > |
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
type |
Type <T2 > |
Type for filtering the nodes |
filter |
Filter |
String or RegExp for filtering the nodes |
Returns
undefined
| T2
match
▸ match(this
, «destructured»
): boolean
Test node type and/or name for a match.
Parameters
Name | Type |
---|---|
this |
T |
«destructured» |
Matcher <T > |
Returns
boolean
nodes
▸ nodes(this
): Generator
<T
, any
, unknown
>
Iterate over all nodes in the hierarchy, including this one.
Parameters
Name | Type |
---|---|
this |
T |
Returns
Generator
<T
, any
, unknown
>
▸ nodes(this
, matcher
): Generator
<T
, any
, unknown
>
Iterate over all nodes in the hierarchy, including this one. Can optionally filter the nodes based on type and/or name.
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
matcher |
Matcher <T > |
Filtering options |
Returns
Generator
<T
, any
, unknown
>
▸ nodes(this
, filter
): Generator
<T
, any
, unknown
>
Iterate over all nodes in the hierarchy, including this one. The iterator skips nodes whose name does not match the provided filter.
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
filter |
Filter |
String or RegExp for filtering the nodes |
Returns
Generator
<T
, any
, unknown
>
▸ nodes<T2
>(this
, type
): Generator
<T2
, any
, unknown
>
Iterate over all nodes in the hierarchy, including this one. The iterator skips nodes whose type does not match the provided type.
Type parameters
Name | Type |
---|---|
T2 |
extends Node <T > |
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
type |
Type <T2 > |
Type for filtering the nodes |
Returns
Generator
<T2
, any
, unknown
>
▸ nodes<T2
>(this
, type
, filter
): Generator
<T2
, any
, unknown
>
Iterate over all nodes in the hierarchy, including this one. The iterator skips nodes whose type does not match the provided type or name does not match the provided filter.
Type parameters
Name | Type |
---|---|
T2 |
extends Node <T > |
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
type |
Type <T2 > |
Type for filtering the nodes |
filter |
Filter |
String or RegExp for filtering the nodes |
Returns
Generator
<T2
, any
, unknown
>
requireNode
▸ requireNode(this
, matcher
): T
Returns the first node from the hierarchy, including this one, that matches the filtering options. Throws an error if the node is not found.
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
matcher |
Matcher <T > |
Filtering options |
Returns
T
▸ requireNode(this
, filter
): T
Returns the first node from the hierarchy, including this one, whose name matches the provided filter. Throws an error if the node is not found.
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
filter |
Filter |
String or RegExp for filtering the nodes |
Returns
T
▸ requireNode<T2
>(this
, type
): T2
Returns the first node from the hierarchy, including this one, whose type matches the provided type. Throws an error if the node is not found.
Type parameters
Name | Type |
---|---|
T2 |
extends Node <T > |
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
type |
Type <T2 > |
Type for filtering the nodes |
Returns
T2
▸ requireNode<T2
>(this
, type
, filter
): T2
Returns the first node from the hierarchy, including this one, whose type matches the provided type and name matches the provided filter. Throws an error if the node is not found.
Type parameters
Name | Type |
---|---|
T2 |
extends Node <T > |
Parameters
Name | Type | Description |
---|---|---|
this |
T |
- |
type |
Type <T2 > |
Type for filtering the nodes |
filter |
Filter |
String or RegExp for filtering the nodes |
Returns
T2