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

tsfiltor

v0.1.5

Published

Composable TypeScript filters for querying and evaluating in-memory data.

Readme

tsfiltor

A composable TypeScript filter system for querying and evaluating in-memory data. Provides a structured way to build complex query conditions that can be evaluated against entities.

Try it live: Go to https://modularizer.github.io/tsfiltor

Features

  • 🎯 Composable filters - Build complex conditions with simple builder functions
  • 🔍 Rich operators - Equality, comparison, string matching, regex, type checking, and more
  • 🧩 Logical operations - AND, OR, NOT with nested conditions
  • 🚀 Array extensions - Optional prototype extensions for fluent API
  • 🔧 Extensible - Register custom operators easily
  • 📦 Type-safe - Full TypeScript support

Installation

npm install tsfiltor

Universal Compatibility

This package is built with dual module support (ESM + CommonJS) for maximum compatibility:

  • Node.js (ESM and CommonJS) - Node 18+
  • Browsers (ESM via CDN or bundlers)
  • React Native (CommonJS) - Full support
  • Bundlers (Webpack, Vite, Rollup, etc.) - Auto-detects format
  • TypeScript (full type support)

The package automatically serves the correct format:

  • import { ... } from 'tsfiltor' → ESM (browsers, modern Node.js, bundlers)
  • const { ... } = require('tsfiltor') → CommonJS (React Native, older tools)

Browser Usage

The package works in browsers via CDN. Use esm.sh or similar CDN:

<script type="module">
  import { eq, gt, filterEntities } from 'https://esm.sh/tsfiltor@latest';
  // Use the library...
</script>

Try it live: Go to https://modularizer.github.io/tsfiltor for an interactive playground with editable examples!

Basic Usage

import { eq, gt, and, or, filterEntities, evaluateCondition } from 'tsfiltor';

const users = [
  { name: 'John', age: 25, status: 'active' },
  { name: 'Jane', age: 30, status: 'active' },
  { name: 'Bob', age: 18, status: 'inactive' },
];

// Build and evaluate conditions
const condition = and(
  eq('status', 'active'),
  gt('age', 20)
);

const activeAdults = filterEntities(users, condition);
// Returns: [{ name: 'John', age: 25, status: 'active' }, ...]

Array Extensions (Optional)

For a more fluent API, you can enable Array prototype extensions. The types are only available when you explicitly import the extensions module:

// Import types and functions - this activates TypeScript support for Array extensions
import 'tsfiltor/extensions';
import { enableArrayExtensions } from 'tsfiltor/extensions';
import { eq, gt, contains } from 'tsfiltor';

// Enable extensions (opt-in)
enableArrayExtensions();

const users = [
    { id: 1, name: 'John Doe', age: 30, email: '[email protected]', status: 'active', tags: ['vip', 'premium'] },
    { id: 2, name: 'Jane Smith', age: 25, email: '[email protected]', status: 'active', tags: ['premium'] },
    { id: 3, name: 'Bob Johnson', age: 18, email: '[email protected]', status: 'inactive', tags: [] },
    { id: 4, name: 'Alice Brown', age: 35, email: '[email protected]', status: 'pending', tags: ['vip'] },
];

// Now arrays have .where(), .first(), .exists(), .count(), and .findWhere()
const activeUsers = users.where(eq('status', 'active'));
const john = users.first(eq('name', 'John'));
const hasVip = users.exists(contains('tags', 'vip'));
const count = users.count(gt('age', 25));

// Chain with native array methods
const names = users
  .where(gt('age', 20))
  .map(u => u.name)
  .sort();

Note:

  • Extensions are opt-in. If you prefer the functional approach, you can use filterEntities(), findFirst(), etc. without enabling extensions.
  • You must import 'tsfiltor/extensions' to get TypeScript type support - the types are NOT included in the main package export.
  • Importing 'tsfiltor/extensions' activates the declare global block, making the Array extension methods available to TypeScript.

Available Operators

Comparison

  • eq(field, value) - Equality
  • ne(field, value) - Not equal
  • lt(field, value) - Less than
  • lte(field, value) - Less than or equal
  • gt(field, value) - Greater than
  • gte(field, value) - Greater than or equal

String Operations

  • contains(field, value) - String/array contains
  • startsWith(field, value) - String starts with
  • endsWith(field, value) - String ends with
  • matches(field, pattern) - Regex pattern match

Array Operations

  • anyOf(field, values[]) - Value is in array
  • minLength(field, n) - Minimum length
  • maxLength(field, n) - Maximum length

Type Checking

  • isRecord(field) - Is plain object/Record
  • matchesZodSchema(field, schema) - Matches Zod schema

Logical

  • and(...conditions) - All conditions must match
  • or(...conditions) - Any condition must match
  • not(condition) - Negate condition

Examples

See the examples directory for more detailed examples:

Custom Operators

Register custom operators for specialized logic:

import { registerOperator, ConditionOperator } from 'tsfiltor';

registerOperator('priceRange', (fieldValue, conditionValue) => {
  const [min, max] = conditionValue;
  return fieldValue >= min && fieldValue <= max;
});

// Use the custom operator
const condition = {
  field: 'price',
  operator: 'priceRange' as ConditionOperator,
  value: [100, 500],
};

API Reference

Core Functions

  • evaluateCondition(entity, condition) - Evaluate condition against entity
  • filterEntities(entities, filter?) - Filter array of entities
  • findFirst(entities, filter?) - Find first matching entity
  • matchExists(entities, filter?) - Check if any entity matches
  • countWhere(entities, filter?) - Count matching entities
  • findWhere(entities, options?) - Find with pagination support

Extension Functions

  • enableArrayExtensions(options?) - Enable Array prototype extensions
  • disableArrayExtensions() - Disable Array prototype extensions
  • registerOperator(operator, evaluator) - Register custom operator

License

Unlicense - This is free and unencumbered software released into the public domain.

For more information, see LICENSE or https://unlicense.org