JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 180
  • Score
    100M100P100Q81711F
  • License ISC

Small library to dynamically create and evaluate expression with multiple parameters (even undefined)

Package Exports

  • safe-evaluate-expression

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (safe-evaluate-expression) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

safe-evaluate-expression

Small library to dynamically create and evaluate expression with multiple parameters (even undefined).

Installation

npm install safe-evaluate-expression

Example

const evaluate = require("safe-evaluate-expression");

const isUndefined = (x) => (x === undefined ? true : false);
const isEqual = (a, b) => a === b;

const operators = { isUndefined, isEqual };
const vars = { a: 1, b: 1, c: 2 };
const params = { ...vars, ...operators };

evaluate("isEqual(a,b)", params); // -> true
evaluate("isEqual(a,c)", params); // -> false
evaluate("isEqual(a,notDefined)", params); // -> false
evaluate("isUndefined(a)", params); // -> false
evaluate("isUndefined(notDefined)", params); // -> true