Skip to content
/ eel Public
forked from networkteam/eel

NPM package @networkteam/eel - Embedded expression language, a parser and compiler for a safe subset of JavaScript for dynamic evaluation in JavaScript.

License

Notifications You must be signed in to change notification settings

Revmaker/eel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@networkteam/eel

Embedded expression language, a parser and compiler for a safe subset of JavaScript for dynamic evaluation in JavaScript.

Features

  • Safe evaluation of JS expressions:
    • !a || (b && c)
    • number == 42
    • foo.bar.baz
    • foo["bar"].baz
    • myFn(1, 2, 3)
    • myObj.method(arg1).prop
  • Compiles expressions from strings to plain JS functions
  • Safe to use with user generated expressions (e.g. as a filter language)
  • Use in the browser or with Node.js

Installation

yarn add @networkteam/eel

or

npm install --save @networkteam/eel

Usage

import { compile } from '@networkteam/eel`

const expr = compile('myVar');

const result = expr({myVar: 'a', 'otherVar': b});

// result === 'a'

Ideally, the expression should be pre-compiled. The generated function can be used with different context values to evaluate the result.

Reference

compile(expression)

expression: string

Compiles the given expression and returns a function that receives the current context for evaluation. The context must be an object that contains all defined variables as properties.

Licence

MIT

About

NPM package @networkteam/eel - Embedded expression language, a parser and compiler for a safe subset of JavaScript for dynamic evaluation in JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 85.9%
  • Nearley 14.1%