AST Monkey Utility

3.1.3 · active · verified Sun Apr 19

ast-monkey-util is a JavaScript utility library that provides a set of helper functions specifically designed for manipulating and navigating Abstract Syntax Trees (ASTs). It is currently at version 3.1.3 and is actively maintained within the Codsen monorepo, indicated by recent copyright updates and ongoing development. The library focuses on granular utilities for path manipulation within nested object structures that represent ASTs, offering functions to determine the next, previous, or parent path, and to identify a parent key. This makes it particularly useful for tasks requiring precise positional awareness without needing full AST traversal or transformation. A key differentiator is its pure ESM distribution, aligning with modern JavaScript module standards, which necessitates a Node.js environment of `v14.18.0` or higher for current versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `ast-monkey-util` functions to navigate and query AST paths, including moving to next/previous siblings, ascending to a parent path, and identifying a parent key.

import { strict as assert } from "assert";
import { pathNext, pathPrev, pathUp, parent } from "ast-monkey-util";

// Example of navigating to the next sibling path
assert.equal(pathNext("9.children.3"), "9.children.4");

// Example of navigating to the previous sibling path
assert.equal(pathPrev("9.children.33"), "9.children.32");

// Example of navigating up to the parent path
assert.equal(pathUp("9.children.1.children.2"), "9.children.1");

// Example of identifying the direct parent key
assert.equal(parent("9.children.3"), "children");

console.log("All assertions passed!");

view raw JSON →