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

wfilter-expr

v1.0.1

Published

过滤条件解析与执行

Readme

wfilter

轻量级过滤表达式编译与执行工具,支持比较操作与逻辑组合,适合对数组数据进行动态筛选。

功能特性

  • 支持比较操作:===!====!=><>=<=
  • 支持集合操作:innotin
  • 支持逻辑组合:any(任一满足)、all(全部满足)
  • 支持将过滤表达式编译为可复用谓词函数

安装

npm install wfilter

核心 API

  • compile(filter):编译过滤表达式,返回谓词函数 (item) => boolean
  • matches(item, filter):判断单个对象是否匹配表达式
  • filterBy(list, filter):按表达式过滤数组

表达式格式

过滤表达式使用元组数组形式:

  • 比较表达式:[op, field, value]
  • 逻辑表达式:['any' | 'all', ...subFilters]

示例:

['>=', 'age', 18]
['in', 'status', ['active', 'trial']]
['all', ['>=', 'age', 18], ['===', 'country', 'CN']]

使用示例

import { compile, matches, filterBy } from 'wfilter';

const users = [
  { id: 1, age: 16, role: 'guest', active: false },
  { id: 2, age: 20, role: 'member', active: true },
  { id: 3, age: 32, role: 'admin', active: true }
];

const expr = ['all', ['>=', 'age', 18], ['in', 'role', ['member', 'admin']]] as const;

const predicate = compile(expr);
const canPass = predicate(users[1]); // true
const oneMatched = matches(users[2], expr); // true
const result = filterBy(users, expr); // id: 2, 3

项目信息

  • 名称:wfilter
  • 描述:过滤条件解析与执行
  • 语言:TypeScript
  • 许可证:MIT