Business Rules
A pricing rule changes every quarter. Right now that's a ticket, a PR, and a deploy. With Bonsai it's a text field in your admin panel that evaluates at runtime.
order.total >= freeShippingThreshold && customer.tier == "gold"
Bonsai gives you a constrained expression language for pricing rules, search filters, workflow conditions, and user-authored logic. Replace fragile eval()-style glue with typed errors, cacheable compilation, and real sandbox controls.
" hello world " |> trim |> upperuser?.profile?.avatar ?? "default.png"users |> filter(.age >= 18) |> map(.name)eval() Would Be RecklessBonsai is strongest when expressions come from config, admin tooling, product builders, or end users and still need to run safely in production.
A pricing rule changes every quarter. Right now that's a ticket, a PR, and a deploy. With Bonsai it's a text field in your admin panel that evaluates at runtime.
order.total >= freeShippingThreshold && customer.tier == "gold"
Users want saved views like "active this week" or "high-value pending." Store the condition as a string, evaluate it per row — no custom query parser needed.
orders |> filter(.status == "pending" && .total > 500)
Your notification service pulls a template from the database and fills it with user data. The expressions live alongside the copy, not buried in application code.
`Hi ${user.firstName}, your order ${order.id} ships ${shipDate |> formatDate}`
You're building a form builder, workflow tool, or internal platform where users configure conditions. They need expression power — you need sandbox controls.
field.country == "US" ? "required" : "hidden"
Not just syntax. Bonsai is designed to be usable in hot paths, safe around untrusted expressions, and boring to ship.
Blocks prototype access, enforces depth and timeout limits. Whitelist or blacklist properties for full control.
Chain transforms with |> for readable data pipelines. Compose trim, upper, filter, map, and more.
Awaits async transforms and functions natively. Mix sync and async operations in a single expression.
Extend with custom transforms and functions. Modular stdlib included for strings, arrays, math, and more.
Lightweight, ESM-only, TypeScript-first. No runtime dependencies - just add and go.
Compile once, cache the AST, and evaluate repeatedly in microseconds with benchmark-gated performance checks.
If your alternative is eval(), handwritten condition trees, or a growing pile of special-case parsers, Bonsai gives you a narrower and more operationally sane surface.
Expressions are parsed as data, not executed as host code. You get property controls, blocked prototype access, depth limits, and explicit safety options.
Compile once, cache the AST, and evaluate repeatedly in microseconds. Use compile() for request handlers, rules engines, and hot loops.
The package is zero-dependency, ESM-only, typed, smoke-tested as a packed artifact, benchmark-gated, and documented with a SemVer stability boundary.
Start from a preset, tweak the expression, then open the full playground with the same context.
{
"name": " hello world "
}
Everything you need to build with Bonsai, from a five-minute quick start to safety guidance, performance notes, and transform/function extension patterns.
Installation, quick start guide, and core concepts.
Literals, operators, pipes, collections, templates, and lambdas.
bonsai(), evaluateSync, compile(), validate(), transforms, and functions.
Strings, arrays, math, types, and dates transforms.
Writing plugins, safety & sandboxing, and performance tips.
Try Bonsai live in your browser with real-time evaluation.