跳到正文

正在自动登录…

← 返回项目列表

Zagorodnyi/filter-ast

过滤器解析

将声明式过滤器对象解析为数据库无关的过滤器AST的库,适用于需要将前端过滤条件转换为统一查询结构的开发者。

AI 中文解读 · 根据仓库描述与 README 生成 · 2026/10/17 09:31:18 · 查看原文

值得看TypeScript库与框架
累计 Stars
65
当前热度
未达当前门槛
仓库创建时间
打开 GitHub ↗项目网站 ↗

选用指南

AI 根据 README 整理 · 2026/10/17 09:31:18

使用方式

通过npm或bun安装,以TypeScript或JavaScript导入命名导出函数使用。

查看 README 依据
# @sirzag/filter-ast Turns a declarative filter object with operator strings into a database-agnostic filter tree. ## Install ```sh npm install @sirzag/filter-ast ``` ```sh bun add @sirzag/filter-ast ``` ## Quick start ```ts import { buildAbstractFilterTree } from "@sirzag/filter-ast"; buildAbstractFilterTree({ status: "$in(active,pending)", age: "$gte(18)", name: "John", }); ``` ```js [ { joinLogic: 'and', conditions: [ { field: 'status', operator: 'in', value: [ 'active', 'pending' ] }, { field: 'age', operator: 'gte', value: 18 },
{ field: 'name', operator: 'eq', value: 'John' } ] } ] ``` The package has named exports only: `buildAbstractFilterTree`, `$and`, `$or`, `joinOr`, `isFilterGroup`, `QueryHelpers`, `FilterError`, and the types `FilterGroup`, `FilterCondition`, `FilterExpression`, `FilterValue`, `FilterFieldValue`, `FilterInput`, `LogicalOperator`, `Operator`, `ParsedOperator`. ## Filter syntax ### Bare values A value that is not an operator string becomes an `eq` condition and is passed through as is. `undefined` fields are dropped. ```ts
部署要求

需要Node.js或Bun环境,支持npm或bun包管理器。

查看 README 依据
# @sirzag/filter-ast Turns a declarative filter object with operator strings into a database-agnostic filter tree. ## Install ```sh npm install @sirzag/filter-ast ``` ```sh bun add @sirzag/filter-ast ``` ## Quick start ```ts import { buildAbstractFilterTree } from "@sirzag/filter-ast"; buildAbstractFilterTree({ status: "$in(active,pending)", age: "$gte(18)", name: "John", }); ``` ```js [ { joinLogic: 'and', conditions: [ { field: 'status', operator: 'in', value: [ 'active', 'pending' ] }, { field: 'age', operator: 'gte', value: 18 },
已知限制

$and和$or仅作为对象字面量的计算键使用,不可复用;输入类型仅编译时检查,运行时不做字段值验证;不提供SQL生成,字段名未消毒,需自行处理。

查看 README 依据
Reproduce with `bun run bench`: builds `dist`, prints the table on Bun, then on Node. Workloads are defined in [`bench/bench.mjs`](./bench/bench.mjs). ## Limitations - `$and` and `$or` work only as computed keys in object literals. They are not reusable symbols: each use creates a new key, so `obj[$and] = { a: 1 }` followed by `obj[$and]` returns `undefined`. - Any symbol key whose description is `"or"` is treated as an OR branch. `{ a: 1, [Symbol("or")]: { b: 2 } }` builds an OR of `a` and `b`.
- Input types are compile-time only. `FilterInput` rejects functions, symbols and plain objects as field values, but field values are not checked at runtime. - There are no adapters and no SQL generation. Field names are passed through unsanitized (`{ "name; DROP TABLE users": "x" }` → `field: 'name; DROP TABLE users'`). Never concatenate them into SQL. ## License [MIT](./LICENSE)

README

正在加载 README…

收录信息

仓库创建时间
2026/10/9 20:05:18
首次达标收录
2026/10/10 09:27:33
统计更新时间
2026/10/22 19:06:16

按创建时长与累计 Stars 判断等级。首次达标收录后,即使未达当前门槛仍保留;累计 Stars 和仓库状态会定期更新。确认只有 README 及辅助文件的仓库会停止公开。

模型评估

值得看加权总分 3.9 / 5

新颖度
3.4
实用价值
4.4
成熟度
4.3
实质含量
3.9

由 Jev 模型根据仓库描述与 README 评估,2026/10/17 09:31:20 生成。评分仅供参考,不是代码、安全或许可证审查;热度等级另按创建时长与累计 Stars 计算。

仓库信息

最近推送
2026/10/10 10:21:00
许可证标识
MIT
Fork 数
0
当前状态
未归档

收录记录

按创建时长与累计 Stars 首次收录:小火
首次发现项目