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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mapeo-entity-filter

v2.0.0

Published

Compiles a filter from a filter expression, for filtering Mapeo entities

Downloads

10

Readme

Mapeo Entity Filter

Build Status npm

This library is forked from mapbox/feature-filter, but adapted to work with entities in the mapeo-core database. 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 tags.

API

compile(filter)

Given a filter expressed as nested arrays, return a new function that evaluates whether a given feature passes its test.

Parameters

| parameter | type | description | | --------- | ----- | ---------------- | | filter | Array | mapbox gl filter |

Returns Function, filter-evaluating function

Usage

var compile = require('mapeo-entity-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 entity = {
  tags: {
    class: "street_limited"
    admin_level: 1
  }
};

// will return a boolean based on whether the feature matched the filter
return testFilter(entity);

Filter expression language

Existential Filters

["has", key] object[key] exists

["!has", key] object[key] does not exist

Comparison Filters

["==", 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

Set Membership Filters

["in", key, v0, ..., vn] set inclusion: object[key] ∈ {v0, ..., vn}

["!in", key, v0, ..., vn] set exclusion: object[key] ∉ {v0, ..., vn}

Combining Filters

["all", f0, ..., fn] logical AND: f0 ∧ ... ∧ fn

["any", f0, ..., fn] logical OR: f0 ∨ ... ∨ fn

["none", f0, ..., fn] logical NOR: ¬f0 ∧ ... ∧ ¬fn

A key must be a string that identifies a entity tag, or one of the following special keys:

  • $type: the entity type. This key may be used with the "==","!=", "in", and "!in" operators. Possible values are "observation", "node", and "way".
  • $id: the entity identifier. This key may be used with the "==","!=", "in", and "!in" operators.
  • $created: the timestamp the entity was created (ISO string).
  • $modified: the timestamp the entity was modified (ISO string).

A value (and v0, ..., vn for set operators) must be a string, number, or boolean to compare the tag 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 tag 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]
]