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

@kevisual/js-filter

v0.0.4

Published

用于 JavaScript 数组的 SQL LIKE 过滤器函数

Downloads

424

Readme

JS Filter

轻量、易读、可解析、可执行的类 SQL 过滤语法,用于 JavaScript 数组过滤。

语法特性

  • WHERE: 条件过滤
  • ORDER BY: 排序
  • LIMIT: 限制结果数量
  • 操作符: =, !=, >, <, >=, <=, IN, CONTAINS, LIKE, NOT LIKE, IS NULL, IS NOT NULL
  • 逻辑: AND, OR

语法示例

// 基础过滤
filter(users, "WHERE metadata.type = 'user'");

// 多条件
filter(users, "WHERE metadata.tags CONTAINS 'premium' AND metadata.region = 'beijing'");

// 排序
filter(users, "WHERE metadata.type = 'user' ORDER BY metadata.created_at DESC");

// 限制数量
filter(users, "WHERE metadata.type = 'user' ORDER BY metadata.created_at DESC LIMIT 10");

// IN 操作
filter(users, "WHERE metadata.region IN ['beijing', 'shanghai']");

// LIKE 操作 (支持 % 匹配任意字符,_ 匹配单个字符)
filter(products, "WHERE name LIKE '%Apple%'");
filter(products, "WHERE name LIKE 'Apple%'");
filter(products, "WHERE name LIKE '%Phone'");

// NOT LIKE 操作 (排除匹配模式的项)
filter(products, "WHERE name NOT LIKE '%Apple%'");

// IS NULL 操作 (匹配 null 或 undefined 的值)
filter(users, "WHERE email IS NULL");

// IS NOT NULL 操作 (匹配非 null 且非 undefined 的值)
filter(users, "WHERE email IS NOT NULL");

使用方法

import { filter } from '@kevisual/js-filter';

const users = [
  {
    metadata: {
      tags: ['premium', 'active'],
      type: 'user',
      region: 'beijing',
      created_at: '2024-03-15T10:00:00Z',
    },
  },
  {
    metadata: {
      tags: ['free'],
      type: 'admin',
      region: 'shanghai',
      created_at: '2024-01-10T09:00:00Z',
    },
  },
  {
    metadata: {
      tags: ['enterprise', 'premium'],
      type: 'user',
      region: 'guangzhou',
      created_at: '2024-04-05T12:00:00Z',
    },
  },
];

// 查找 premium 用户
const premiumUsers = filter(users, "WHERE metadata.tags CONTAINS 'premium'");

// 查找北京的用户,按创建时间倒序
const beijingUsers = filter(users, "WHERE metadata.region = 'beijing' ORDER BY metadata.created_at DESC");

新增操作符说明

NOT LIKE

排除匹配指定模式的数据项。

// 查找不包含 "Apple" 的产品
const nonAppleProducts = filter(products, "WHERE name NOT LIKE '%Apple%'");

IS NULL / IS NOT NULL

检查字段值是否为 nullundefined

const usersWithNullEmail = [
  { name: 'Alice', email: '[email protected]', age: 25 },
  { name: 'Bob', email: null, age: 30 },
  { name: 'Charlie', email: undefined, age: 35 },
];

// 查找 email 为 null 或 undefined 的用户
const usersWithoutEmail = filter(usersWithNullEmail, "WHERE email IS NULL");

// 查找 email 不为 null 且不为 undefined 的用户  
const usersWithEmail = filter(usersWithNullEmail, "WHERE email IS NOT NULL");

注意: IS NULLIS NOT NULL 会同时检查 JavaScript 的 nullundefined 值。