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-specificity

v0.1.1

Published

Matched-constraint specificity: score how many atomic constraints in a @wildwinter/expr condition are actively holding it true. Shared by Storylet Studio (storylet draw priority) and Patter (dialogue best-match).

Readme

@wildwinter/expr-specificity

Matched-constraint specificity for @wildwinter/expr conditions: score how many atomic constraints in a condition are actively holding it true against the current state.

This is an evaluation-aware score, not a static clause count. An or's score depends on which branch is currently matching; an and sums the constraints that must all hold. It is the primitive behind Storylet Studio's storylet draw priority and Patter's dialogue best-match, which had independently grown the same algorithm.

The package is tiny and deliberately ignorant of evaluation: you pass an ExprNode and an evalTruthy closure that says whether a subtree currently holds. Your closure owns the eval context, the dialect, and your truthiness rule, so this package never needs to know them.

Install

npm install @wildwinter/expr-specificity

@wildwinter/expr is a peer dependency (you already have it - the AST comes from there).

Usage

import { evaluate, deserialiseAst } from "@wildwinter/expr";
import { matchedSpecificity } from "@wildwinter/expr-specificity";

const node = deserialiseAst(condition.ast);

// Host-bound truthiness: evaluate a subtree and coerce to a boolean however
// your host does (Storylets: non-zero number or true; Patter: its `truthy`).
const evalTruthy = (n) => conditionPasses(evaluate(n, ctx, dialect));

const score = matchedSpecificity(node, evalTruthy);
// `@x == 5 and @y > 3` with both holding -> 2
// `@a == 1 or @b == 1`  with either holding -> 1

The walk

The score is a recursive walk carrying a polarity flag want ("the truth value this subtree must have for the whole condition to hold"), starting true at the root. De Morgan is applied as it descends:

| Node | Rule | |---|---| | atom (comparison, scoped var, literal, non-counting call) | 1 if its truth matches want, else 0 | | and | under want: both must hold -> left + right, else 0; under !want: behaves as or | | or | under want: strongest branch -> max(left, right); under !want: behaves as and | | not | recurse into the operand with want flipped | | counting call (default: check_flags) | its operand count when it must hold and does, else the negated rules |

check_flags(v, f1..fN) counts as N constraints (an N-ary AND over the flag operands, args.length - 1, min 1). Add or replace counting calls via the countingCalls option.

API

  • matchedSpecificity(node, evalTruthy, opts?) => number
  • opts.want - root polarity (default true; production only scores eligible conditions).
  • opts.countingCalls - calls scored by operand count (default [CHECK_FLAGS_COUNTING_CALL]).
  • CHECK_FLAGS_COUNTING_CALL - the built-in check_flags rule.
  • Types: EvalTruthy, CountingCall, MatchedSpecificityOptions.

License

MIT