A Node.js package that lets you evaluate JavaScript code with enhanced features like Python-style operator overloading, custom imports, and export-based returns.
npm install eval-magicA Node.js package that lets you evaluate JavaScript code with enhanced features like Python-style operator overloading, custom imports, and export-based returns.
``shell`
npm install eval-magic
`javascript
import { evaluate } from "eval-magic";
const result = evaluate(
export const sum = x + y;,
{ x: 10, y: 20 }
);
console.log(result); // { sum: 30 }
`
`javascript
import { compile, Py } from "eval-magic";
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
Py.__add__ {
return new Point(this.x + other.x, this.y + other.y);
}
}
const compiled = compile(
const p1 = new Point(1, 2);
const p2 = new Point(3, 4);
export const result = p1 + p2;,
{ Point }
);
console.log(compiled.run()); // { result: Point(4, 6) }
`
- API Reference - Complete documentation for compile, evaluate, and all configuration options
- Magic Method Operators - Comprehensive guide to Python-style operator overloading
Perfect for developers working with:
- Domain-Specific Languages (DSLs)
- Creative coding and mathematical expressions
- Sandbox-like script evaluation
- Custom operator behaviors
ā ļø This package evaluates arbitrary JavaScript code. Security is your responsibility - validate and sanitize input in production environments.
- [ ] Allow compiled functions to be called with different globals` several times without re-compilation
- [ ] Improve await detection for better async behavior control