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/js

v1.1.2

Published

Filtron helper: transform filter expressions into JavaScript predicates for Array.filter()

Readme

@filtron/js

Convert Filtron AST to JavaScript filter predicates for use with Array.filter().

npm version npm bundle size codecov

Installation

npm install @filtron/js

Usage

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

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

if (result.success) {
  const filter = toFilter(result.ast);

  const users = [
    { name: "Alice", age: 25, status: "active" },
    { name: "Bob", age: 16, status: "active" },
  ];

  users.filter(filter);
  // => [{ name: "Alice", age: 25, status: "active" }]
}

API

toFilter<T>(ast, options?): (item: T) => boolean

Converts a Filtron AST to a predicate function.

Options

| Option | Type | Default | Description | | ----------------- | ------------------------------------ | ----------- | ----------------------------------------------------------- | | allowedFields | string[] | undefined | Whitelist of queryable fields (throws if field not in list) | | fieldAccessor | (obj: T, field: string) => unknown | undefined | Custom function to retrieve field values | | caseInsensitive | boolean | false | Case-insensitive string comparisons | | fieldMapping | Record<string, string> | undefined | Map query field names to object property names |

Examples

Restrict allowed fields:

const filter = toFilter(ast, {
  allowedFields: ["name", "email", "age"],
});
// Querying "password" will throw an error

Case-insensitive matching:

const filter = toFilter(ast, {
  caseInsensitive: true,
});
// "status = 'ACTIVE'" matches { status: "active" }

Field mapping:

const filter = toFilter(ast, {
  fieldMapping: {
    email: "emailAddress",
    age: "userAge",
  },
});
// Query "email" maps to object property "emailAddress"

Combined options:

const filter = toFilter(ast, {
  fieldMapping: { user_email: "email" },
  allowedFields: ["user_email"],  // Validates against query field names
  caseInsensitive: true,
});

nestedAccessor(separator?): FieldAccessor

Creates a field accessor for dot-notation nested properties:

import { toFilter, nestedAccessor } from "@filtron/js";

const filter = toFilter(ast, {
  fieldAccessor: nestedAccessor(),
});

// Query: "user.profile.age > 18"
// Matches: { user: { profile: { age: 25 } } }

Custom separator:

const filter = toFilter(ast, {
  fieldAccessor: nestedAccessor("/"),
});
// Query: "user/profile/age > 18"

Security

When accepting user input, use allowedFields to prevent access to sensitive properties:

const filter = toFilter(ast, {
  allowedFields: ["name", "email", "status"],
});
// Queries against "password", "token", etc. will throw

License

MIT