
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
Filtron helper: transform filter expressions into JavaScript predicates for Array.filter()
Convert Filtron AST to JavaScript filter predicates for use with Array.filter().
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" },
];
users.filter(filter);
// => [{ name: "Alice", age: 25, status: "active" }]
}
toFilter<T>(ast, options?): (item: T) => booleanConverts a Filtron AST to a predicate function.
| Option | Type | Default | Description |
|---|---|---|---|
allowedFields | string[] | undefined | Whitelist of queryable fields (throws if field not in list) |
fieldAccessor | (obj: T, field: string) => unknown | undefined | Custom function to retrieve field values |
caseInsensitive | boolean | false | Case-insensitive string comparisons |
fieldMapping | Record<string, string> | undefined | Map query field names to object property names |
Restrict allowed fields:
const filter = toFilter(ast, {
allowedFields: ["name", "email", "age"],
});
// Querying "password" will throw an error
Case-insensitive matching:
const filter = toFilter(ast, {
caseInsensitive: true,
});
// "status = 'ACTIVE'" matches { status: "active" }
Field mapping:
const filter = toFilter(ast, {
fieldMapping: {
email: "emailAddress",
age: "userAge",
},
});
// Query "email" maps to object property "emailAddress"
Combined options:
const filter = toFilter(ast, {
fieldMapping: { user_email: "email" },
allowedFields: ["user_email"], // Validates against query field names
caseInsensitive: true,
});
nestedAccessor(separator?): FieldAccessorCreates 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 } } }
Custom separator:
const filter = toFilter(ast, {
fieldAccessor: nestedAccessor("/"),
});
// Query: "user/profile/age > 18"
When accepting user input, use allowedFields to prevent access to sensitive properties:
const filter = toFilter(ast, {
allowedFields: ["name", "email", "status"],
});
// Queries against "password", "token", etc. will throw
MIT
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.