Skip to content

Extended grammar for JEXL (Javascript Expression Language)

License

Notifications You must be signed in to change notification settings

nikoraes/jexl-extended

Repository files navigation

Jexl Extended Grammar

This package includes an extended grammar for the Jexl expression parser and evaluator.

Installation

npm install jexl-extended

Usage

Use the entire library as you would the original Jexl library, but import from jexl-extended instead of jexl.

import jexl from 'jexl-extended';

const result = jexl.evalSync('[{name:"tek",age:32}, {name:"bar",age:34}, {name:"baz",age:33}, {name:"foo",age:35}]|map("value.age")');
// [32, 34, 33, 35]

It is also possible to use the extended grammar in the original Jexl library by importing parts of the grammar you need and adding it to the Jexl instance.

import jexl from 'jexl';
import { arrayMap } from 'jexl-extended/extended-grammar';

jexl.addTransform('map', arrayMap);
const result = jexl.evalSync('[{name:"tek",age:32}, {name:"bar",age:34}, {name:"baz",age:33}, {name:"foo",age:35}]|map("value.age")');
// [32, 34, 33, 35]