
Security News
TeamPCP Is Systematically Targeting Security Tools Across the OSS Ecosystem
TeamPCP is targeting security tools across the OSS ecosystem, turning scanners and CI pipelines into infostealers to access enterprise secrets.
@filtron/js
Advanced tools
In-memory JavaScript array filtering using Filtron AST.
bun add @filtron/js
# or
npm install @filtron/js
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" },
];
const filtered = users.filter(filter);
// [{ name: "Alice", age: 25, status: "active" }]
}
toFilter(ast, options?)Converts a Filtron AST to a predicate function for use with Array.filter().
Options:
| Option | Type | Description |
|---|---|---|
allowedFields | string[] | Restrict queryable fields (throws if field not in list) |
fieldAccessor | (obj, field) => unknown | Custom field value accessor |
caseInsensitive | boolean | Case-insensitive string comparisons (default: false) |
fieldMapping | Record<string, string> | Map query field names to object property names |
const filter = toFilter(ast, {
allowedFields: ["name", "email", "age"],
caseInsensitive: true,
});
nestedAccessor(separator?)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 } } }
Map query field names to different object property names. This is useful when you want to expose a different API in your queries than your internal data structure:
import { parse } from "@filtron/core";
import { toFilter } from "@filtron/js";
const result = parse('email = "user@example.com" AND age > 18');
if (result.success) {
const filter = toFilter(result.ast, {
fieldMapping: {
email: "emailAddress",
age: "userAge",
},
});
const users = [
{ emailAddress: "user@example.com", userAge: 25 },
{ emailAddress: "other@example.com", userAge: 16 },
];
const filtered = users.filter(filter);
// [{ emailAddress: "user@example.com", userAge: 25 }]
}
Field mapping works with all expression types and can be combined with other options:
const filter = toFilter(ast, {
fieldMapping: {
user_id: "id",
user_email: "email",
},
allowedFields: ["user_id", "user_email"], // Validation uses query field names (before mapping)
caseInsensitive: true,
});
When accepting user input, use allowedFields to prevent access to sensitive fields:
const filter = toFilter(ast, {
allowedFields: ["name", "email", "status"], // "password" queries will throw
});
FAQs
Filtron helper: transform filter expressions into JavaScript predicates for Array.filter()
The npm package @filtron/js receives a total of 4 weekly downloads. As such, @filtron/js popularity was classified as not popular.
We found that @filtron/js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
TeamPCP is targeting security tools across the OSS ecosystem, turning scanners and CI pipelines into infostealers to access enterprise secrets.

Security News
TypeScript 6.0 introduces new standard APIs, modern default settings, and deprecations as it prepares projects for the upcoming TypeScript 7.0 release.

Security News
/Research
Newly published Trivy Docker images (0.69.4, 0.69.5, and 0.69.6) were found to contain infostealer IOCs and were pushed to Docker Hub without corresponding GitHub releases.