Find all Unist Nodes After a Specific Point

5.0.0 · active · verified Sun Apr 19

unist-util-find-all-after is a utility from the unified collective designed to locate all unist (Universal Syntax Tree) nodes that appear after a specified child node or index within a parent node. Its current stable version is 5.0.0, which requires Node.js 16 or higher and is ESM-only. The unified collective typically ties major releases to Node.js LTS cycles, providing stable maintenance. This package differentiates itself as a highly focused, lightweight utility for tree traversal, intended for integration within the broader unified ecosystem, offering a small, composable piece of functionality rather than a comprehensive tree manipulation library. It's fully typed with TypeScript and works alongside other `unist-util-*` packages like `unist-util-is` for node testing.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use `findAllAfter` to find specific 'leaf' nodes occurring after a given index within a unist tree structure, using `unist-builder` to construct the tree.

import { u } from 'unist-builder';
import { findAllAfter } from 'unist-util-find-all-after';

const tree = u('tree', [
  u('leaf', 'leaf 1'),
  u('parent', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),
  u('leaf', 'leaf 4'),
  u('parent', [u('leaf', 'leaf 5')]),
  u('leaf', 'leaf 6'),
  u('empty'),
  u('leaf', 'leaf 7')
]);

// Find all 'leaf' nodes after the node at index 1 (which is a 'parent' node)
const result = findAllAfter(tree, 1, 'leaf');

console.log(JSON.stringify(result, null, 2));
/*
Expected output:
[
  {
    "type": "leaf",
    "value": "leaf 4"
  },
  {
    "type": "leaf",
    "value": "leaf 6"
  },
  {
    "type": "leaf",
    "value": "leaf 7"
  }
]
*/

view raw JSON →