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

@wildwinter/expr

v0.3.0

Published

Agnostic expression engine: parse, unparse, evaluate, and serialise a small condition/effect expression language. Scopes and built-in functions are injected via a Dialect.

Readme

@wildwinter/expr

A small, agnostic expression engine - parse, unparse, evaluate, and serialise a condition/effect expression language. The grammar, operators, and evaluator are fixed and generic; the scope tokens and built-in functions are injected via a Dialect, so the same core powers different host projects.

It was extracted from Storylet Studio's expression engine and generalised so that both Storylet Studio and Patter can share it. Zero runtime dependencies; ESM + CJS + types.

import { parse, evaluate, unparse, compile, type Dialect } from "@wildwinter/expr";

const dialect: Dialect = {
  defaultScope: "shared",                 // bare @name -> @shared.name
  scopes: [{ token: "shared" }, { token: "scene" }, { token: "flow" }],
  functions: {
    max: {
      minArgs: 2, maxArgs: 2, returnType: "number",
      eval: (args, h) => Math.max(h.evaluate(args[0]) as number, h.evaluate(args[1]) as number),
    },
  },
};

const node = parse("@hp < 10 and @scene.alarm", dialect);
evaluate(node, { scopes: { shared: { hp: 5 }, scene: { alarm: true } } }, dialect); // true
unparse(node, { defaultScope: "shared" });            // "@hp < 10 and @scene.alarm"
compile("@hp > 0", dialect);                          // { src, ast: ["bin", ">", ...] }  (bundle form)

The language

  • Literals: true / false, numbers (42, 3.14), strings ('x' or "x"). A bare identifier with no ( is sugar for a string (@season == winter).
  • Property refs: @name (the dialect's default scope) or @scope.name. Names are lowercased.
  • Operators: and or not (short-circuit; aliases && || !), comparisons == != > >= < <= (= is an alias for ==), arithmetic + - * / (+ also concatenates strings).
  • Functions: dialect-supplied. A function may declare flagDeltaArgs so its trailing args parse as +flag / -flag (reaching eval as flagdelta nodes).

API

  • parse(src, dialect): ExprNode - text to AST (throws ParseError).
  • unparse(node, { defaultScope? }): string - AST to canonical text (round-trip stable).
  • evaluate(node, ctx, dialect): ScalarValue - walk the AST against ctx.scopes + ctx.host.
  • serialiseAst(node) / deserialiseAst(node) - to/from the compact tagged-tuple bundle form.
  • compile(src, dialect): { src, ast } - parse + serialise (the publish/compile step).

Dialect

interface ScopeDef    { token: string; missing?: "false" | "throw" }   // missing-prop policy; default "false"
interface FunctionDef {
  minArgs: number; maxArgs?: number;
  returnType: "boolean" | "number" | "string" | "flags" | "unknown";
  flagDeltaArgs?: boolean;
  eval(rawArgs: ExprNode[], h: { evaluate; ctx }): ScalarValue;         // raw args; call h.evaluate(arg) as needed
}
interface Dialect     { scopes: ScopeDef[]; defaultScope: string; functions: Record<string, FunctionDef> }

A scope absent from the context resolves to false. A property missing from a present scope follows that scope's missing policy.

License

MIT (c) Ian Thomas.