json-logic-engine
Version:
Construct complex rules with JSON & process them.
42 lines (41 loc) • 1.32 kB
TypeScript
/**
* Allows you to configure precision for JSON Logic Engine.
*
* You can pass the following in:
* - `ieee754` - Uses the IEEE 754 standard for calculations.
* - `precise` - Tries to improve accuracy of calculations by scaling numbers during operations.
* - A constructor for decimal.js.
*
* @example ```js
* import { LogicEngine, configurePrecision } from 'json-logic-js'
* import { Decimal } from 'decimal.js' // or decimal.js-light
*
* const engine = new LogicEngine()
* configurePrecision(engine, Decimal)
* ```
*
* The class this mechanism uses requires the following methods to be implemented:
* - `eq`
* - `gt`
* - `gte`
* - `lt`
* - `lte`
* - `plus`
* - `minus`
* - `mul`
* - `div`
* - `mod`
* - `toNumber`
*
* ### FAQ:
*
* Q: Why is this not included in the class?
*
* A: This mechanism reimplements a handful of operators. Keeping this method separate makes it possible to tree-shake this code out
* if you don't need it.
*
* @param {import('../logic.d.ts').default | import('../asyncLogic.d.ts').default} engine
* @param {'precise' | 'ieee754' | (...args: any[]) => any} constructor
* @param {Boolean} compatible
*/
export function configurePrecision(engine: any | any, constructor: "precise" | "ieee754" | ((...args: any[]) => any), compatible?: boolean): void;