0.1.16 • Published 5 months ago

@bouygues-telecom/spl v0.1.16

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

Simple Predicate Langage (SPL)

NPM Version

Introduction

SPL is a very small, lightweight, straightforward and non-evaluated expression language to sort, filter and paginate arrays of maps.

Grammar

See SPL.g4 file

Examples

Given this simple dataset:

const dataset = [
  {
    firstName: "Martin",
    lastName: "Dupont",
    age: 21,
    address: {
      country: "France",
      town: "Paris",
    },
  },
  {
    firstName: "Bertrand",
    lastName: "Dupont",
    age: 17,
    address: {
      country: "South Korea",
      town: "Seoul",
    },
  },
  {
    firstName: "Michel",
    lastName: "Dupond",
    age: 19,
    address: {
      country: "France",
      town: "Toulouse",
    },
  },
]

The following expressions can be applied using SPL:

Filters

Simple filtering

lastName = 'Dupont'

Binary operators

(firstName = 'Seb') AND (lastName = 'Dupont')

Array search

(firstName IN ['Seb', 'Paul', 'Jean']) OR (lastName = 'Dupont')

Inject fields anywhere

(givenName IN [firstName, lastName]) OR (lastName = 'Dupont')

Inject variables anywhere

(givenName IN [:variable1, :variable2]) OR (lastName = :variable3)

Deep search

address.country = 'France'

Sort

SORT BY firstName ASC, lastName DESC

Pagination

LIMIT 0, 100
0.1.16

5 months ago

0.1.15

5 months ago

0.1.14

5 months ago

0.1.12

5 months ago

0.1.10

5 months ago

0.1.9

5 months ago

1.0.0

5 months ago