@accuser/hast-util-type-guards
v1.0.0
Published
TypeScript type guards for `hast` nodes.
Downloads
18
Readme
TypeScript Type Guards for Hast Nodes
This package provides TypeScript type guards for Hast nodes.
Installation
npm install @accuser/hast-util-type-guards
Usage
import { isText } from '@accuser/hast-util-type-guards';
const value = {
type: 'text',
value: 'Hello, world!'
};
isNode(value); // true, value is Node
isLiteral(value); // true, value is Literal
isText(value); // true, value is Text
API
This package exports the identifiers:
There is no default export.
isComment(value: unknown): value is Comment
Test if the given value is a valid Comment
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Comment
node.
isDoctype(value: unknown): value is Doctype
Test if the given value is a valid Doctype
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Doctype
node.
isElement(value: unknown): value is Element
Test if the given value is a valid Element
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Element
node.
isLiteral(value: unknown): value is Literal
Test is a given value is a valid Literal
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Unist literal value.
isNode(value: unknown): value is Node
Test if a given value is a valid Node
.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Node
.
isParent(value: unknown): value is Parent
Test is a given value is a valid Parent
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Parent
node.
isRoot(value: unknown): value is Root
Test if a given value is a valid Root
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Root
node.
isText(value: unknown): value is Text
Test if a given value is a valid Text
node.
Parameters
value
(unknown
)- value to check.
Returns
Returns true
if value
is a valid Text
node.
Tests
npm test