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

safe-expr-eval

v1.0.4

Published

Secure expression evaluator - Drop-in replacement for expr-eval without CVE-2025-12735 vulnerability

Readme

safe-expr-eval

Fast and lightweight expression evaluator for JavaScript and TypeScript.

A modern expression parser with a familiar API, zero dependencies, and full TypeScript support.


Features

  • Fast expression parsing and evaluation
  • Lightweight and dependency-free
  • Full TypeScript support
  • Simple and familiar API
  • Custom functions and constants
  • ES2020+ compatible
  • Well tested

Installation

npm install safe-expr-eval

Quick Start

Basic Usage

import { Parser } from 'safe-expr-eval';

const parser = new Parser();
const expr = parser.parse('2 * x + 1');

console.log(expr.evaluate({ x: 3 })); // 7
console.log(expr.evaluate({ x: 10 })); // 21

Direct Evaluation

import { evaluate } from 'safe-expr-eval';

const result = evaluate('10 + 5 * 2');

console.log(result); // 20

Compiled Expressions

import { compile } from 'safe-expr-eval';

const fn = compile('price * quantity * (1 - discount)');

console.log(
  fn({
    price: 100,
    quantity: 2,
    discount: 0.1
  })
); // 180

Supported Operations

Arithmetic

+  -  *  /  %

Comparison

==  !=  >  <  >=  <=

Logical

and  or  not
&&   ||   !

Data Types

Numbers   → 42, 3.14
Strings   → "hello"
Booleans  → true, false
Variables → price, user.name

Custom Functions

const parser = new Parser();

parser.functions.max = Math.max;
parser.functions.min = Math.min;
parser.functions.round = Math.round;

const expr = parser.parse(
  'round(max(a, b) * 1.5)'
);

console.log(
  expr.evaluate({
    a: 10,
    b: 20
  })
); // 30

Constants

const parser = new Parser();

parser.consts.PI = Math.PI;
parser.consts.TAX_RATE = 0.15;

const expr = parser.parse(
  'price * (1 + TAX_RATE)'
);

console.log(
  expr.evaluate({
    price: 100
  })
); // 115

API

Parser

Create parser

new Parser()

Parse expression

parser.parse(expression)

Evaluate expression

parser.evaluate(expression, variables?)

Functions registry

parser.functions

Constants registry

parser.consts

Standalone Functions

evaluate

evaluate(expression, variables?)

compile

compile(expression)

Testing

npm test
npm run test:coverage

License

MIT

See the LICENSE file for details.


Contributing

Pull requests and contributions are welcome.


Issues

Please open an issue if you find a bug or have a feature request.


Author

Alejandro Castrillon

GitHub: https://github.com/