npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@imogenz/escalc

v0.0.1-beta.2

Published

NCalc expression evaluator

Readme

escalc

npm Downloads

escalc is an opinionated NCalc expression evaluator in TypeScript. It exposes a parser, a tree-walk evaluator, a formatter, and a parameter extractor for a well-defined subset of the NCalc expression language.

Designed for a small footprint and fast execution with zero dependencies.

Install

npm install @imogenz/escalc
# or
pnpm add @imogenz/escalc
# or
yarn add @imogenz/escalc

Quick start

import { evaluate } from "@imogenz/escalc";

// Basic arithmetic
evaluate("1 + 2"); // => 3
evaluate("2 ** 8"); // => 256
evaluate("Max(Abs(-5), 2)"); // => 5

// Parameters
evaluate("[price] * (1 + [tax])", {
  params: new Map([
    ["price", 100],
    ["tax", 0.2],
  ]),
}); // => 120

// Safe variant - no throwing
import { evaluateSafe } from "@imogenz/escalc";
const result = evaluateSafe(userInput);
if (result.type === "success") console.log(result.result);

Demos

See the Demos guide for complete real-world examples.

See also

Implementation

Created using a recursive descent parser with a handwritten lexer and tree-walk evaluator. The parser supports error recovery: with stopOnFirstError: false it collects all recoverable errors and returns a partial AST via incompleteExpression.

Support matrix

| Feature | Status | | ------------------------------------------------ | --------------------------------------- | | Arithmetic (+ - * / % **) | ✅ | | Comparison (> < >= <= == !=) | ✅ | | Logical (&& \|\| !) with short-circuit | ✅ | | Bitwise (& \| ^ << >> ~) | ✅ | | Ternary (? :) | ✅ | | in / not in | ✅ | | String / number / boolean / date / list literals | ✅ | | Parameter references ([name], {name}) | ✅ | | Built-in math functions (Abs, Sin, Sqrt, …) | ✅ | | if / ifs conditional functions | ✅ | | Custom functions | ✅ | | Lazy parameters | ✅ | | Custom operator implementation (Calculator) | ✅ | | Result caching | ❌ won't implement - cache at call site | | GUID value type | ❌ won't implement - use a string |

See Supported Features for the full reference.

Equivalent NCalc flags

| NCalc flag | ESCalc equivalent | | ----------------------------------- | -------------------------------------------------- | | EvaluateOptions.IterateParameters | Not supported | | EvaluateOptions.IgnoreCase | Not supported - parameter names are case-sensitive | | EvaluateOptions.NoCache | Default behaviour (no caching) | | EvaluateOptions.RoundAwayFromZero | Override Calculator.modulus / Round | | Custom function handler | functions option in evaluate / execute | | Custom value factory | Extend StandardCalculator |

How to extend behaviour

Override the provided Calculator interface or extend StandardCalculator to change how operators work. Extend AbstractVisitor<T> for custom AST traversal.

See Overriding Evaluation for examples.

License

MIT License © 2026 ImogenZ