https://github.com/adbayb/esvisitor
An ECMAScript module to visit any hashmap-like structure (AST, custom tree, ...) and apply some algorithms
https://github.com/adbayb/esvisitor
Last synced: 3 months ago
JSON representation
An ECMAScript module to visit any hashmap-like structure (AST, custom tree, ...) and apply some algorithms
- Host: GitHub
- URL: https://github.com/adbayb/esvisitor
- Owner: adbayb
- License: mit
- Created: 2024-02-11T23:02:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-17T02:25:27.000Z (over 1 year ago)
- Last Synced: 2024-11-09T18:12:54.371Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 198 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
An ECMAScript module to visit any hashmap-like structure (AST, custom tree, ...) and apply some algorithms
## ✨ Features
- Tiny module with zero dependencies (less than 300B 🚀)
- Apply the visitor design pattern in a functional way with ease
- Data structure agnostic (a custom tree, a parser-specific abstract syntax tree, ...).
Any hashmap-like structure can be visited as long as each node exposes a `type` field
## 🚀 Quickstart
1️⃣ Install the library:
```bash
# Npm
npm install esvisitor
# Pnpm
pnpm add esvisitor
# Yarn
yarn add esvisitor
```2️⃣ Once you're done, you can play with the API:
```ts
import { visit } from "esvisitor";visit(
{
type: "Root",
value: {
type: "Array",
value: [
{
type: "Variable",
value: "Hello",
},
],
},
},
{
Array(node) {
console.log("Array node: ", node);
},
Root(node) {
console.log("Root node: ", node);
},
Variable(node) {
console.log("Variable node: ", node);
},
},
);type Nodes = {
Array: Node<"Array", Nodes["Variable"][]>;
Root: Node<"Root", Nodes["Array"][]>;
Variable: Node<"Variable", string>;
};type Node = {
type: Type;
value: Value;
};
```_You can check the [examples](https://github.com/adbayb/esvisitor/tree/main/examples) folder for different hashmap structure processing (including parser-specific abstract syntax trees)._
## ✍️ Contribution
We're open to new contributions, you can find more details [here](https://github.com/adbayb/esvisitor/blob/main/CONTRIBUTING.md).
## 📖 License
[MIT](https://github.com/adbayb/esvisitor/blob/main/LICENSE "License MIT")