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

whereql

v0.1.0

Published

A small filter-expression language with two agreeing backends: parse once, then translate to SQL or evaluate in memory with SQL three-valued semantics.

Downloads

220

Readme

whereql

A small filter-expression language, with two backends that agree with each other: parse once, then either translate to SQL or evaluate in memory against a plain object.

status in ('ACTIVE','PENDING') and country eq 'GBR' and createdAt gte '2026-01-01'
const { parse, matches, mergeFilter } = require('whereql');

const ast = parse("status eq 'ACTIVE' and amount gte 1000");
matches(ast, { status: 'ACTIVE', amount: 2500 }); // true
mergeFilter("city eq 'London'", "status eq 'ACTIVE'");
// → "(city eq 'London') and (status eq 'ACTIVE')"

Why it exists

A service that filters lists in the database, but also has to judge a single record in-process — before a write, say — needs the same predicate answered twice, in two places. A separate parser and a hand-written comparison drift apart, and the drift is invisible until the two disagree about one row.

This package is the single definition: one grammar, one AST, two backends.

API

| Export | Purpose | |---|---| | parse(input, opts?) | expression → AST. Throws FilterSyntaxError | | matches(ast, record, opts?) | does this record satisfy the expression? | | evaluate(ast, record, opts?) | three-valued result — true \| false \| 'unknown' | | mergeFilter(existing, extra) | AND-merge, parenthesised | | mergeAll(...exprs) | AND-merge several, skipping empties | | inClause(field, values) | build field in ('a','b') | | quote(value) | single-quote, escaping ''' | | referencedFields(ast) | which fields the expression needs | | tokenize(input) | tokens, if you need them |

Operatorseq, ne, contains, gt, gte, lt, lte, in, not_in, with and / or and parentheses. and binds tighter than or.

Literals — strings single-quoted with '' as an escaped quote; bare numbers; ISO-8601 dates in quotes.

Limits — 2048 bytes, nesting depth 16, 128 AST nodes by default. The defaults suit an expression carried in a query string; raise them when it travels somewhere roomier:

parse(input, { maxBytes: 8192, maxDepth: 64, maxNodes: 512 });

Exceeding a limit throws. Nothing is silently truncated, because shortening a not_in list would widen what the expression permits rather than narrow it — the one direction a length guard must never move.

Two things that are easy to get wrong

SQL is three-valued. city ne 'London' is UNKNOWN when city IS NULL, and WHERE keeps only rows where the predicate is TRUE — so the row is excluded. A naive record.city !== 'London' returns true and admits exactly the row the database filtered out.

matches() treats UNKNOWN as not a match, which keeps the two backends in agreement and fails closed when a record is missing a field the expression tests. Use evaluate() when you need to tell "excluded" from "undecidable".

Date.parse is not a date test. V8 parses 'CD-1' to a real timestamp — and 'cd-1' to the same one. Sniffing for dates with Date.parse alone therefore made two unrelated reference codes compare equal. Both operands must match a strict ISO-8601 shape before either is treated as an instant.

Field whitelists are not included, deliberately

What fields an endpoint accepts, and which operators are legal on each, is data owned by whoever owns the table. Centralising it here would mean a package release for every new filterable column, and a stale copy would wrongly reject valid expressions.

This package defines the grammar. Validate fields against your own whitelist after parsing — referencedFields() is there for that.

Case sensitivity

String comparison is case-sensitive by default. For columns stored upper-cased, pass the field names so in-memory comparison matches what the database does:

matches(ast, record, { caseInsensitiveFields: ['sku', 'countryCode'] });

contains is always case-insensitive, mirroring ILIKE.

Module format

CommonJS. Every consumer today is CJS, and an ESM-only build would fail there with ERR_REQUIRE_ESM. A dual build can wait until an ESM consumer exists.

Verifying against a SQL translator

test/parser-differential.manual.ts compares this parser's AST with another implementation's, expression by expression. It is not part of npm test because it reaches outside the package.

Still outstanding: a differential test of matches() against a live database running the translated SQL. Reasoning about NULL semantics by reading the code is how that bug ships.