This package has been deprecated

Author message:

Warning: This project has been renamed to filter-expressions. Install using filter-expressions instead.

json-filter-expressions

0.0.1 • Public • Published

Overview

Simple util to provide the ability to evaluate targets based on simple evaluation conditions expressed as arrays.

Example

The below example shows the simple filter expressions on a collection.

// Import evaluate from the library
import { evaluate } from 'json-filter-expressions';

// JSON definition of filter
const json = {
  "filter": ["all", ["==", "type", "document"], ["in", "tags", "example", "other"]]
}

// Example objects
const objects = [
  { type: "document", src: "https://alpacamaps/document1.json", tags: ["example"] },
  { type: "document", src: "https://alpacamaps/document2.json", tags: ["something"] },
  { type: "document", src: "https://alpacamaps/document3.json", tags: ["other"] },
  { type: "image", src: "https://alpacamaps/image.png", tags: ["example"] }
]

// Match the objects
const matched = evaluate(json.filter, objects);
// Returns [
//   { type: "document", src: "https://alpacamaps/document1.json", tags: ["example"] },
//   { type: "document", src: "https://alpacamaps/document3.json", tags: ["other"] }
// ]

Supported Evaluators

  • Existence: exists / exist / !exists / !exist
  • Comparison: == / != / > / >= / < / <=
  • Membership: in / !in
  • Combining: all / any / none

Notes

  • Comparisons are done as using lodash "isEqual".
  • Run npm t to run tests
  • Inspired based on mapbox style filters

/json-filter-expressions/

    Package Sidebar

    Install

    npm i json-filter-expressions

    Weekly Downloads

    0

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • cammanderson