smart-filter-builder
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

smart-filter-builder

Example

import { After, Is, LessThan } from "smart-filter-builder/filters";
import { And, Or } from "smart-filter-builder/operators";
import { Field } from "smart-filter-builder/sources";
import { predicateToCEL } from "smart-filter-builder/utilities";

const incompatibleBrowser = And(
  Field("user.lastSeen", After(Temporal.Now.instant().subtract({ months: 1 }))),
  Or(
    And(
      Or(
        Field("browser.name", Is("Chrome")),
        Field("browser.name", Is("Edge"))
      ),
      Field("browser.version", LessThan(79))
    ),
    And(
      Field("browser.name", Is("Firefox")),
      Field("browser.version", LessThan(67))
    ),
    And(
      Field("browser.name", Is("Safari")),
      Field("browser.version", LessThan(13))
    )
  )
);

incompatibleBrowser({ browser: { name: "Safari", version: "12" } }); // => true
predicateToCEL(incompatibleBrowser); // => (browser.name == "Chrome" || browser.name == "Edge") && browser.version < 79 || browser.name == "Firefox" && browser.version < 67 || browser.name == "Safari" && browser.version < 13

Readme

Keywords

none

Package Sidebar

Install

npm i smart-filter-builder

Weekly Downloads

0

Version

0.3.3

License

Apache-2.0

Unpacked Size

95.6 kB

Total Files

135

Last publish

Collaborators

  • ericmantooth