Subscript is a modular and extensible expression parser and evaluator for JavaScript and TypeScript. It provides a lightweight core for building custom Domain Specific Languages (DSLs) and offers several ready-to-use presets, including `subscript` (common expressions), `justin` (JSON, templates, arrow functions, optional chaining), and `jessie` (a JavaScript subset supporting statements, functions, and control flow). The package is currently at version 10.3.2 and maintains an active release cadence with frequent minor and major updates introducing new syntax features, performance improvements, and API refinements. Key differentiators include its small bundle size (~2KB core), high performance for both parsing and evaluation, a minimal JSON-compatible Abstract Syntax Tree (AST), and built-in sandboxing to prevent prototype pollution and global access. It is designed to be universal, fast, and safe, making it suitable for templates, calculators, safe evaluation environments, and language subsets.
npm install subscriptVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing and evaluating a Jessie preset expression with functions and control flow, showcasing sandboxed execution and context passing.
Migrate your import statements from `const pkg = require('pkg')` to `import pkg from 'pkg'` or `import { named } from 'pkg'`. If using Node.js, ensure your package.json specifies `"type": "module"` or use `.mjs` file extensions.Consult the `spec.md` and release changelogs for the specific version you are targeting to understand the new AST format. Update your custom logic to align with the revised node kinds and structures.
Refer to the `docs.md` for the current API on extending Subscript. Use the explicit `binary('op', precedence)` and `operator('op', (a,b)=>...)` methods for registering new syntax and their compilation logic, as shown in the README example.If you serialize/deserialize Subscript ASTs, update your deserialization logic to account for the new regex and `undefined` formats. This is primarily a concern for storage or network transfer of ASTs.
Do not attempt to access or manipulate global objects or the prototype chain within Subscript expressions. Design your expressions and provided context (`ctx` object) to contain only necessary and safe data/functions.
Change `const subscript = require('subscript')` to `import subscript from 'subscript'`. Ensure your Node.js environment or build setup correctly handles ES modules (e.g., `"type": "module"` in `package.json`).If the feature is standard JavaScript, try using the `justin` or `jessie` presets. If it's a custom or domain-specific operator, you'll need to extend the parser using `binary`, `unary`, or `nary` registration methods.
Modify the expression to avoid accessing these properties. The sandbox is intentional. Ensure your expression logic operates strictly within the provided context and its safe members.
Consult the `spec.md` file in the `subscript` repository for the specific version you are using to understand the current AST structure. Update any custom AST traversal, transformation, or compilation logic accordingly.
No dependency data recorded yet.