Index

eva

Functions to create functions and evaluate expressions.

NPM version Built with Grunt

Installation

Node

npm install eva

Component

component install gamtiq/eva

Jam

jam install eva

Bower

bower install eva

AMD, <script>

Use dist/eva.js or dist/eva.min.js (minified version).

Usage

Node, Component

var eva = require("eva");

Jam

require(["eva"], function(eva) {
    ...
});

AMD

define(["path/to/dist/eva.js"], function(eva) {
    ...
});

Bower, <script>


<!-- Use bower_components/eva/dist/eva.js if the library was installed by Bower -->

<script type="text/javascript" src="path/to/dist/eva.js"></script>
<script type="text/javascript">
    // eva is available via eva field of window object
    ...
</script>

Examples

var func = eva.createFunction("(a || 0) + (b || 0) + (c || 0)", {paramNames: "a, b, c", expression: true});
console.log(func("abc"));   // abc00
console.log(func(10, 1, 5, 8));   // 16

func = eva.createFunction("if (obj.b) {return a + b;} else {return 'a=' + a;}", {scope: true, paramNames: "obj"});
console.log( func({a: "a", b: "bc"}) );   // abc

console.log( eva.evalWith("this.a + this.b", {a: 1, b: 9}) );   // 10
console.log( eva.evalWith("fn(this.expr)", {expr: "Math.sin(0)"}, {fn: eva.evalWith}) );   // 0

var obj = {};
eva.createDelegateMethod(eva, "evalWith", {destination: obj, destinationMethod: "expr"});
console.log( obj.expr("Math.cos(0)") );   // 1

API

createFunction(code: String, [settings: Object]): Function

Create function to further use.

evalWith(expression: String, [context: Object], [scope: Object])

Calculate/evaluate value of specified expression using given context and scope.

createDelegateMethod(delegate: Object, method: String, [settings: Object]): Function

Create function that executes specified method of the given object.

See doc folder for details.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

Copyright (c) 2014 Denis Sikuler
Licensed under the MIT license.

Copyright (c) 2014 Denis Sikuler
Documentation generated by JSDoc 3.2.2 on Sun Apr 13 2014 21:14:19 GMT+0400 (MSK) using the DocStrap template.