Skip to content

This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.

Installation

Terminal window
npm install solve-engine

The package ships both ESM and CommonJS builds with TypeScript declarations for each, so it works whether your project uses import or require.

Node 22 or newer, or any browser from the last few years. The engine has no DOM dependency and no Node-specific dependency, so the same build runs in a browser tab, a web worker, a Node process, or a serverless function.

TypeScript is optional. If you use it, everything is typed and no separate @types package is needed.

import { createEngine } from "solve-engine";
const engine = createEngine({ locale: "en" });
const result = engine.evaluateExpression("2 + 2 * 10");
console.log(result.toNumber()); // 22

If that prints 22, you are set up.

The main entry gives you the engine and the common types. There are also focused subpath entries, so a bundler only pulls in the part you actually use.

ImportContains
solve-engineExpressionEngine, createEngine, IEnginePackage, common types
solve-engine/vmValue, ValueType, and value construction helpers
solve-engine/formatformatValue and formatting settings
solve-engine/languageEditor support: completions, token categories, highlighting
solve-engine/packagesThe built-in packages and their configuration types
solve-engine/constantsEngine configuration defaults and the engine version
solve-engine/errorsThe structured error type and its taxonomy

A further set of entries exposes the pipeline internals for advanced use, listed in subpath exports. Anything not documented there is internal and can change between releases without a major version.

Every feature in this reference comes from a package: money and tax from FINANCE_PACKAGE, colours from COLOUR_PACKAGE, dates from DATETIME_PACKAGE, and so on. An engine registers exactly the packages you give it and nothing else, so your bundler drops the built-ins you never use.

For the common case, createEngine() is batteries-included: it registers the full built-in set in one call.

import { createEngine } from "solve-engine";
const engine = createEngine(); // every built-in package

To keep the built-ins and add your own package on top, pass it as extraPackages rather than assembling the list by hand:

import { createEngine } from "solve-engine";
import { myPackage } from "./my-package";
const engine = createEngine({ extraPackages: [myPackage] });

For a smaller bundle, construct the engine with only the packages you need. Importing them from solve-engine/packages lets the bundler tree-shake the rest away.

import { ExpressionEngine } from "solve-engine";
import { ARITHMETIC_PACKAGE, UOM_PACKAGE } from "solve-engine/packages";
// Only arithmetic and units reach the bundle.
const engine = new ExpressionEngine({ packages: [ARITHMETIC_PACKAGE, UOM_PACKAGE] });

Each syntax page names the package (or packages) its grammar needs, so you can add just those: the Package note near the top of a page lists what to register for that feature.

Currency conversion, weather and stock lookups reach the network. Currency and weather work out of the box against free, keyless endpoints. Stocks, crypto and the knowledge package are opt-in and require you to supply the fetching function yourself, which means the engine never holds an API key. See async and live data.

To evaluate an expression or a whole note from a terminal or a CI job, without writing a host around the engine, use the solve command: solve "5 km in miles" prints 3.11 miles, and solve check notes.md exits with a failure status when one of the note’s check lines stops holding. It is a package of its own; the command line covers it.