jexl-extended
Version:
Extended grammar for Javascript Expression Language (JEXL)
79 lines (54 loc) ⢠2.82 kB
Markdown
This package includes an extended grammar for the [Jexl expression parser and evaluator](https://github.com/TomFrost/Jexl) by TomFrost.
š **[Complete Documentation](https://docs.konnektr.io/docs/jexl)** | š® **[Try the Playground](https://jexl-playground.konnektr.io/)**
- š **80+ Built-in Functions** - String manipulation, math, arrays, objects, dates, and more
- šØ **Monaco Editor Support** - Syntax highlighting, IntelliSense, and hover documentation
- š **TypeScript Support** - Full type definitions included
- š§ **Modular** - Use the entire library or import individual functions
- š® **Interactive Playground** - Try expressions online at [jexl-playground.konnektr.io](https://jexl-playground.konnektr.io/)
```bash
npm install jexl-extended
```
```javascript
import jexl from 'jexl-extended';
const data = [
{name: "John", age: 32},
{name: "Jane", age: 34},
{name: "Bob", age: 33}
];
const result = jexl.evalSync('data|filter("value.age > 32")|map("value.name")|join(", ")', {data});
// "Jane, Bob"
```
Get a rich IDE experience for JEXL expressions:
```typescript
import * as monaco from 'monaco-editor';
import { Monaco } from 'jexl-extended';
// Register JEXL language support
Monaco.registerJexlLanguage(monaco);
// Create editor with JEXL support
const editor = Monaco.createJexlEditor(monaco, document.getElementById('editor'), {
value: 'users|filter("value.active")|map("value.name")|sort',
theme: 'vs-dark'
});
```
[š See full Monaco integration guide](https://docs.konnektr.io/docs/jexl/usage/monaco-integration)
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.
```javascript
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]
```
This extended grammar is also available in other programming languages:
- **C
- **Python**: [pyjexl-extended](https://github.com/nikoraes/pyjexl-extended) - Python implementation with extended functions and transforms
- [Jexl](https://github.com/TomFrost/Jexl) - The original JavaScript implementation of JEXL that this library extends
- [jexl-rs](https://github.com/mozilla/jexl-rs) - A Rust-based JEXL parser and evaluator
- [PyJEXL](https://github.com/mozilla/pyjexl) - Mozilla's Python-based JEXL parser and evaluator