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

simple-expressions

v1.1.0

Published

Simple expression parsing and execution

Readme

simple-expressions

simple-expressions logo

npm license

A small, dependency-free CommonJS library for parsing and evaluating simple expressions against a model object.

Install

npm install simple-expressions

Requires Node.js 20 or later.

Usage

const { executeExpression, parseExpression } = require('simple-expressions');

const model = { user: { name: 'Ada' }, score: 8 };

executeExpression(model, 'and(eq(#user.name, "Ada"), gt(#score, 5))');
// true

const evaluator = parseExpression('concat("Hello, ", #user.name)');
evaluator(model);
// "Hello, Ada"

executeExpression(model, expression) always returns a boolean. parseExpression(expression) returns a reusable evaluator and preserves the expression result's type.

Demo

Try the interactive playground at simple-expressions.liesel.dev.

The demo lets you edit a JSON model and expression, then evaluates the expression in your browser using the package source bundled locally for the site. It showcases both boolean expressions and value-producing expressions such as concat, len, lower, upper, and if.

To run the demo locally:

npm install
npm run demo

The demo is a client-side showcase, not a security boundary. As with the library itself, expression text and regular-expression patterns should be treated as trusted input.

Expression Syntax

Constants:

  • true and false, case-insensitive
  • Numeric literals, including signed, decimal, and exponent values
  • Strings quoted with single quotes, double quotes, or backticks
  • Lists enclosed in square brackets, with comma-separated expressions such as ["yes", lower("NO"), #value]

Model references start with #. Nested values use dots, such as #user.name. A literal own key such as "user.name" takes precedence over nested traversal. References only resolve own properties; inherited values are never read. The segments __proto__, constructor, and prototype are rejected.

Operators are case-insensitive:

| Operator | Arguments | Behavior | | --- | --- | --- | | not | 1 | Logical negation. | | eq | 2 | Loose equality (==), with structural equality for lists. | | or | 2+ | Logical OR with short-circuit evaluation. | | and | 2+ | Logical AND with short-circuit evaluation. | | contains | 2 | Case-sensitive string containment; the left value must be a string. | | startswith | 2 | Case-sensitive string prefix matching; the left value must be a string. | | endswith | 2 | Case-sensitive string suffix matching; the left value must be a string. | | in | 2 | True when the first value is present in the second value, which must be a list; comparisons use the same loose equality as eq. | | gt | 2 | JavaScript greater-than comparison. | | lt | 2 | JavaScript less-than comparison. | | empty | 1 | True for null, undefined, and empty strings. | | len | 1 | A string length or an own length property; throws otherwise. | | lower | 1 | Converts a value to lowercase text; falsey values become empty strings. | | upper | 1 | Converts a value to uppercase text; falsey values become empty strings. | | trim | 1 | Trims surrounding whitespace; nullish values remain unchanged and other falsey values become empty strings. | | defined | 1 | True for every value except null and undefined. | | concat | 2+ | Concatenates truthy values after calling toString(); falsy values become empty strings. | | match | 2 | Tests a value against a JavaScript regular expression pattern. | | if | 3 | Returns the second or third argument based on the truthiness of the first; only the selected branch is evaluated. |

Unquoted identifiers are operators and must be followed by parentheses. They are not string constants.

Caching

Parsed expressions and SimpleExpression instances are cached by default. Each cache is bounded to 1,000 entries and evicts the oldest entry when full. Use SimpleExpressions.setCacheLimit(limit) to set a positive safe-integer limit; lowering it immediately evicts the oldest existing entries. A limit of zero or less disables caching, the same as disableCaches(), which also clears existing entries. Use SimpleExpressions.clear() or enableCaches() to manage this behavior when needed.

Security

Expressions and regular-expression patterns are trusted input. match accepts JavaScript regex patterns from expression literals and model values. Invalid patterns throw, and untrusted patterns can cause excessive CPU use through catastrophic backtracking (ReDoS). Do not use this package as an untrusted-input validation or authorization boundary.

Conformance

Cross-language compatibility is tested in the independent simple-expressions-conformance repository. This package has no filesystem or checkout dependency on the C# and Dart implementations.

The conformance specification is versioned and maintained independently. See the conformance repository for the corpus, adapter contract, and cross-language CI.

Development

npm test
npm run pack:check
npm run release

npm test rebuilds the published output before running the test suite. npm run pack:check shows the files that would be included in a release. npm run release creates the package tarball and publishes it to npm.