
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
compile-filter
Advanced tools
This library is forked from mapbox/feature-filter, but adapted to work with any object. This library implements the semantics specified by the Mapbox GL JS spec, but supports arrays as keys as well as strings, in order to filter against nested properties
compile(filter)
Given a filter expressed as nested arrays, return a new function that evaluates whether a given feature passes its test.
| parameter | type | description |
|---|---|---|
filter | Array | mapbox gl filter |
Returns Function, filter-evaluating function
var compile = require('compile-filter');
// will match a feature with class of street_limited,
// AND an admin_level less than or equal to 3,
// that's NOT a polygon.
var filter = [
"all",
["==", "class", "street_limited"],
["<=", "admin_level", 3]
]
// testFilter will be a function that returns a boolean
var testFilter = compile(filter);
// Layer feature that you're testing. Must have type
// and properties keys.
var feature = {
class: "street_limited"
admin_level: 1
};
// will return a boolean based on whether the feature matched the filter
return testFilter(feature);
["has", key] object[key] exists
["!has", key] object[key] does not exist
["==", key, value] equality: object[key] = value
["!=", key, value] inequality: object[key] â value
[">", key, value] greater than: object[key] > value
[">=", key, value] greater than or equal: object[key] ⼠value
["<", key, value] less than: object[key] < value
["<=", key, value] less than or equal: object[key] ⤠value
["in", key, v0, ..., vn] set inclusion: object[key] â {v0, ..., vn}
["!in", key, v0, ..., vn] set exclusion: object[key] â {v0, ..., vn}
["all", f0, ..., fn] logical AND: f0 â§ ... â§ fn
["any", f0, ..., fn] logical OR: f0 ⨠... ⨠fn
["none", f0, ..., fn] logical NOR: ÂŹf0 â§ ... â§ ÂŹfn
A value (and v0, ..., vn for set operators) must be a string, number, or boolean to compare the property value against.
Set membership filters are a compact and efficient way to test whether a field matches any of multiple values.
The comparison and set membership filters implement strictly-typed comparisons; for example, all of the following evaluate to false: 0 < "1", 2 == "2", "true" in [true, false].
The "all", "any", and "none" filter operators are used to create compound filters. The values f0, ..., fn must be filter expressions themselves.
["==", "class", "street_major"]
This filter requires that the class property of each feature is equal to either "street_major", "street_minor", or "street_limited".
["in", "class", "street_major", "street_minor", "street_limited"]
The combining filter "all" takes the three other filters that follow it and requires all of them to be true for a feature to be included: a feature must have a class equal to "street_limited", its admin_level must be greater than or equal to 3.
[
"all",
["==", "class", "street_limited"],
[">=", "admin_level", 3]
]
FAQs
Compiles a filter from a filter expression, for array filtering
The npm package compile-filter receives a total of 0 weekly downloads. As such, compile-filter popularity was classified as not popular.
We found that compile-filter demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.