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

@filtron/core

v2.0.0

Published

Filtron parses human-friendly filter strings into structured queries you can use anywhere — SQL databases, in-memory arrays, or your own custom backend.

Readme

@filtron/core

A fast, human-friendly filter language for JavaScript and TypeScript. Parse expressions like age > 18 AND verified into a type-safe AST.

npm version npm bundle size codecov

Why Filtron?

Let users filter data with readable expressions:

price < 100 AND category : ["electronics", "books"] AND inStock

Filtron parses these expressions into a structured AST you can use to generate SQL, filter arrays, or build custom query backends — safely, with no risk of injection attacks.

Filtron works best when your data has dynamic or user-defined fields that aren't part of your type system: e-commerce catalogs, log aggregation, CMS taxonomies, or multi-tenant platforms with custom metadata.

Installation

npm install @filtron/core

Optional helpers:

  • @filtron/sql — Generate parameterized SQL WHERE clauses
  • @filtron/js — Filter JavaScript arrays in-memory

Usage

import { parse } from "@filtron/core";

const result = parse('age > 18 AND status = "active"');

if (result.success) {
	console.log(result.ast);
} else {
	console.error(result.error);
}

Syntax

// Comparisons
parse("age > 18");
parse('status = "active"');
parse('role != "guest"');

// Boolean logic
parse("age > 18 AND verified");
parse("admin OR moderator");
parse("NOT suspended");
parse("(admin OR mod) AND active");

// Field existence
parse("email?");
parse("profile EXISTS");

// Contains (substring)
parse('name ~ "john"');

// One-of (IN)
parse('status : ["pending", "approved"]');

// Ranges
parse("age = 18..65");
parse("price = 9.99..99.99");

// Nested fields
parse("user.profile.age >= 18");

Operators

| Operator | Meaning | Example | | -------------------- | ------------- | --------------------- | | =, : | Equal | status = "active" | | !=, !: | Not equal | role != "guest" | | >, >=, <, <= | Comparison | age >= 18 | | ~ | Contains | name ~ "john" | | ?, EXISTS | Field exists | email? | | .. | Range | age = 18..65 | | : [...] | One of | status : ["a", "b"] | | AND, OR, NOT | Boolean logic | a AND (b OR c) |

API

parse(input: string): ParseResult

Parses a filter expression and returns a result object.

const result = parse("age > 18");

if (result.success) {
	result.ast; // ASTNode
} else {
	result.error; // string - error message
	result.position; // number - position in input where error occurred
}

parseOrThrow(input: string): ASTNode

Parses a filter expression, throwing FiltronParseError on invalid input.

import { parseOrThrow, FiltronParseError } from "@filtron/core";

try {
	const ast = parseOrThrow("age > 18");
} catch (error) {
	if (error instanceof FiltronParseError) {
		console.error(error.message); // error description
		console.error(error.position); // position in input where error occurred
	}
}

Types

All AST types are exported for building custom consumers:

import {
	FiltronParseError, // Error class thrown by parseOrThrow
	type ParseResult,
	type ASTNode,
	type AndExpression,
	type OrExpression,
	type NotExpression,
	type ComparisonExpression,
	type ExistsExpression,
	type BooleanFieldExpression,
	type OneOfExpression,
	type NotOneOfExpression,
	type RangeExpression,
	type Value,
	type ComparisonOperator,
	type StringValue,
	type NumberValue,
	type BooleanValue,
	type IdentifierValue,
} from "@filtron/core";

The Lexer types are also available if you want to use them for syntax highlighting or other purposes:

import { Lexer, LexerError } from "@filtron/core";
import type { Token, TokenType, StringToken, NumberToken, BooleanToken } from "@filtron/core";

AST structure

| Node Type | Fields | Example input | | -------------- | ---------------------------- | ---------------------- | | and | left, right | a AND b | | or | left, right | a OR b | | not | expression | NOT a | | comparison | field, operator, value | age > 18 | | exists | field | email? | | booleanField | field | verified | | oneOf | field, values | status : ["a", "b"] | | notOneOf | field, values | status !: ["a", "b"] | | range | field, min, max | age = 18..65 |

Example output:

parse('age > 18 AND status = "active"')

// Returns:
{
  success: true,
  ast: {
    type: "and",
    left: {
      type: "comparison",
      field: "age",
      operator: ">",
      value: { type: "number", value: 18 }
    },
    right: {
      type: "comparison",
      field: "status",
      operator: "=",
      value: { type: "string", value: "active" }
    }
  }
}

Performance

Recursive descent parser. ~9 KB minified, zero dependencies.

| Query complexity | Parse time | Throughput | | ---------------- | ---------- | ----------------- | | Simple | ~90-250ns | 4-11M ops/sec | | Medium | ~360-870ns | 1.1-2.8M ops/sec | | Complex | ~0.9-1.5μs | 650K-1.1M ops/sec |

License

MIT