@accuser/mdast-util-directive-type-guards
v1.0.0
Published
TypeScript type guards for `mdast` directive nodes.
Downloads
5
Maintainers
Readme
TypeScript Type Guards for Mdast Directive Nodes
This package provides TypeScript type guards for Mdast Directive nodes.
Installation
npm install @accuser/mdast-util-directive-type-guards
Usage
import { isTextDirective } from '@accuser/mdast-util-directive-type-guards';
const node = {
type: 'textDirective',
name: 'foo',
children: [{ type: 'text', value: 'Hello, world!' }]
} as unknown;
if (isTextDirective(node)) {
// node is TextDirective
}
API
This package exports the identifiers:
There is no default export.
isContainerDirective(node: unknown): node is ContainerDirective
Test if a given value is a valid Mdast ContainerDirective
node.
Parameters
node
(unknown
)- value to check.
Returns
Returns true
if node
is a valid ContainerDirective
node.
Example
import { isContainerDirective } from '@accuser/mdast-util-directive-type-guards';
const node = {
type: 'containerDirective',
name: 'foo',
children: [{ type: 'text', value: 'Hello, world!' }]
} as unknown;
if (isContainerDirective(node)) {
console.log(node.name); // 'foo'
console.log(node.children[0]); // { type: 'text', value: 'Hello, world!' }
}
isLeftDirective(node: unknown): node is LeftDirective
Test if a given value is a valid Mdast LeafDirective
node.
Parameters
node
(unknown
)- value to check.
Returns
Returns true
if node
is a valid LeafDirective
node.
Example
import { isLeafDirective } from '@accuser/mdast-util-directive-type-guards';
const node = {
type: 'textDirective',
name: 'foo',
children: [{ type: 'text', value: 'Hello, world!' }]
} as unknown;
if (isLeafDirective(node)) {
console.log(node.name); // 'foo'
console.log(node.children[0]); // { type: 'text', value: 'Hello, world!' }
}
isTextDirective(node: unknown): node is TextDirective
Test if a given value is a valid Mdast TextDirective
node.
Parameters
node
(unknown
)- value to check.
Returns
Returns true
if node
is a valid TextDirective
node.
Example
import { isTextDirective } from '@accuser/mdast-util-directive-type-guards';
const node = {
type: 'textDirective',
name: 'foo',
children: [{ type: 'text', value: 'Hello, world!' }]
} as unknown;
if (isTextDirective(node)) {
console.log(node.name); // 'foo'
console.log(node.children[0]); // { type: 'text', value: 'Hello, world!' }
}
Tests
npm test