1.1.0 • Published 10 months ago

@accuser/unist-util-type-guards v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

License

MIT

1.1.0

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago