evaluateExpression

Evaluates a compiled expression with the given parameter values, or returns NaN when it cannot.

@internote/canvas-sdkFunction
On this page
import { evaluateExpression } from '@internote/canvas-sdk';

expr is the js of a refined expression, as the compiler emitted it: a body over Math and the parameter names, such as Math.sin(x) * a. It is checked against that grammar before it runs, so an expression that is not one evaluates to NaN rather than running. A result that is not a number is NaN too.

#Signature

(expr: string, params: Record<string, number>): number

#Parameters

expr
The expression's JavaScript, as a refined expression's js.
params
The value of each parameter the expression may name, by name.

#Returns

The number the expression comes to, or NaN.

#Example

const y = evaluateExpression(curve.js, { ...ctx.parameters.numbers(), x: 2 });

Declared in packages/canvas-sdk/src/maths/index.ts:35.

Last updated