@accuser/unist-util-type-guards
v1.1.0
Published
TypeScript type guards for `unist` nodes.
Downloads
27
Readme
TypeScript Type Guards for Unist Nodes
This package provides TypeScript type guards for Unist nodes.
Installation
npm install @accuser/unist-util-type-guards
Usage
import { isNode } from '@accuser/unist-util-type-guards';
const node = {
type: 'leaf',
value: 'Leaf'
};
isNode(node); // true, node is Node
isLiteral(node); // true, node is Literal
isParent(node); // false
API
This package exports the following identifiers:
There is no default export.
isLiteral(value: unknown): node is Literal
Test is the given value is a valid Literal
.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Literal
.
isMonoparous(value: unknown): value is Parent
Test is a given value is a valid Parent
with exactly one child.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Parent
with exactly one child.
isMultiparous(value: unknown): value is Parent
Test is a given value is a valid Parent
with more than one child.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Parent
with more than one child.
isNode(value: unknown): value is Node
Test is a given value is a valid Node
.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Node
.
isNulliparous(value: unknown): value is Parent
Test is a given value is a valid Parent
with no children.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Parent
with no children.
isParent(value: unknown): value is Parent
Test is a given value is a valid Parent
.
Parameters
node
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Parent
.
Tests
npm test