47 lines
942 B
Markdown
47 lines
942 B
Markdown
# Graph with Reflection and Rewrite Nodes
|
||
|
||
This project provides a minimal directed graph implementation that supports two special node types:
|
||
|
||
- **ReflectionNode** – passes its input unchanged to its output.
|
||
- **RewriteNode** – transforms its input using a user‑supplied function.
|
||
|
||
## Installation
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
## Usage
|
||
|
||
```js
|
||
import { Graph, ReflectionNode, RewriteNode } from './src/index.js';
|
||
|
||
const graph = new Graph();
|
||
|
||
// Create nodes
|
||
const start = new ReflectionNode('start');
|
||
const rewrite = new RewriteNode('rewrite', (x) => x * 2);
|
||
|
||
// Add nodes to graph
|
||
graph.addNode(start);
|
||
graph.addNode(rewrite);
|
||
|
||
// Connect nodes
|
||
graph.addEdge('start', 'rewrite');
|
||
|
||
// Evaluate graph
|
||
const result = graph.evaluate();
|
||
console.log(result); // { start: undefined, rewrite: 0 } (example)
|
||
```
|
||
|
||
## Running Tests
|
||
|
||
A simple test script (`test.js`) can be added to validate functionality. Run:
|
||
|
||
```bash
|
||
npm test
|
||
```
|
||
|
||
## License
|
||
|
||
MIT |