Skip to content

brandnetworks/expression-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Expression Parser

This library is a tiny expresssion parser an evaluator for both Node.js and the browser.

It was originally extracted form the Angular.js expression parser so it supports Angular filter expressions such as:

name|replace:"Mr":"Mrs"

Features

  • Arithmethic and logical operators
  • Ternary Operator
  • Object and array literals
  • Object and array member evaluation
  • Function calls through filter expressions

Examples

// On Node.js
var Parser = require('expression-parser').Parser;
var parser = new Parser();
var $eval = parser.parse('name|replace:"Mr":"Mrs"');
$eval({name: 'Mr. Asimov'}, {
  replace: function(text, substr, repl) { return text.replace(substr, repl); }
});
// > 'Mrs. Asimov'
var $eval = parser.parse('1 + 2 + 8/4');
$eval();
// > 5
// On the browser
var parser = new ExpressionParser.Parser();
var $eval = parser.parse('name|replace:"Mr":"Mrs"');
$eval({name: 'Mr. Asimov'}, {
  replace: function(text, substr, repl) { return text.replace(substr, repl); }
});
// > 'Mrs. Asimov'
var $eval = parser.parse('1 + 2 + 8/4');
$eval();
// > 5

For more examples check the tests.

About

An expression parser and evaluator for Node.js and the browser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published