0.1.16 • Published 5 months ago
@bouygues-telecom/spl v0.1.16
Simple Predicate Langage (SPL)
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 DESCPagination
LIMIT 0, 100