@thi.ng/units
Version:
Extensible SI unit creation, conversions, quantities & calculations (incl. List-like DSL and ~170 predefined units & constants)
43 lines • 1.62 kB
TypeScript
/**
* Parses & evaluates given Lisp-like formula expression to compute, combine or
* convert units in a more concise style than the default JS API provided by
* this package.
*
* @remarks
* The minimal domain specific language defined here only includes the following
* functions (all following basic Lisp syntax, also see examples below):
*
* - Math operators: `+`, `-`, `*`, `/` to combine two or more quantities (all
* quantities MUST be compatible)
* - `area`: Computes the area of a given 2D quantity (e.g. `(area DIN_A4)`
* computes the area of a sheet of paper)
* - `volume`: Computes the volume of a given 3D quantity
* - `width`: Returns the 1st dimension quantity of a 2D/3D quantity (e.g.
* `(width DIN_A4)` = 210mm)
* - `height`: Returns the 2nd dimension quantity of a 2D/3D quantity
* - `depth`: Returns the 3rd dimension quantity of a 3D quantity
*
* Any other symbol is interpreted as quantity or pre-defined registered unit or
* constant (see readme).
*
* @example
* ```ts tangle:../export/eval.ts
* import { $eval } from "@thi.ng/units";
*
* // compute weight in grams of A4 paper with 320 grams per square meter
* console.log($eval(`(g (* (area DIN_A4) 320gsm))`));
* // 19.9584
*
* // compute weight in kg of 1/2 inch thick 200x300mm glass plate
* console.log($eval(`(kg (* 200mm 300mm 0.5in 2500kg/m3))`));
* // 1.905
*
* // same as previous but using the `glass` density preset
* console.log($eval(`(kg (* 200mm 300mm 0.5in glass))`));
* // 1.905
* ```
*
* @param src
*/
export declare const $eval: (src: string) => any;
//# sourceMappingURL=dsl.d.ts.map