@bygdle/expr-parser

0.9.7 • Public • Published

Expr parser

Parses and evaluates mathematical expressions with custom functions and variables.

https://github.com/NiuWeb/expr-parser

Installation

npm install @bygdle/expr-parser

Usage example

import { Parser } from "@bygdle/expr-parser"
const parser = new Parser({
  functions: {
    log: { // a custom function log
      arguments: 1,
      evaluate: ([arg]) => {
        return Math.log(arg)
      }
    }
  },
  variables: {
    pi: Math.PI
  }
})

const expr = parser.parse("log(pi) + 1")
console.log(expr.evaluate())

parset.setVar("pi", 3)
console.log(expr.evaluate())

Readme

Keywords

none

Package Sidebar

Install

npm i @bygdle/expr-parser

Weekly Downloads

39

Version

0.9.7

License

none

Unpacked Size

561 kB

Total Files

126

Last publish

Collaborators

  • bygdle