This package provides TypeScript type guards for Mdast Directive nodes.
npm install @accuser/mdast-util-directive-type-guards
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
}
This package exports the identifiers:
There is no default export.
Test if a given value is a valid Mdast ContainerDirective
node.
node
(unknown
)- value to check.
Returns true
if node
is a valid ContainerDirective
node.
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!' }
}
Test if a given value is a valid Mdast LeafDirective
node.
node
(unknown
)- value to check.
Returns true
if node
is a valid LeafDirective
node.
import { isLeafDirective } from '@accuser/mdast-util-directive-type-guards';
const node = {
type: 'leafDirective',
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!' }
}
Test if a given value is a valid Mdast TextDirective
node.
node
(unknown
)- value to check.
Returns true
if node
is a valid TextDirective
node.
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!' }
}
npm test