@susisu/ts-dimensional
v0.1.0
Published
Dimensional Quantities in TypeScript
Downloads
3
Readme
@susisu/ts-dimensional
PoC: Dimensional Quantities in TypeScript
NOTE: This is an experimental package and not suitable for production use.
npm i @susisu/ts-dimensional
# or
yarn add @susisu/ts-dimensional
TypeScript 4.0+ is required.
Example
import { mass, length, mks, cgs, add, mul, conv } from "@susisu/ts-dimensional";
const m1 = mass(1, mks);
const m2 = mass(2, mks);
const m3 = mass(3, cgs);
const l1 = length(1, mks);
const l2 = length(2, mks);
const l3 = length(3, cgs);
add(m1, m2); // ok
add(m1, l1); // error: dimensions mismatch
add(m1, m3); // error: unit systems mismatch
mul(m1, l1); // ok
add(mul(m1, l1), mul(m2, l2)); // ok
mul(m1, l3); // error: unit systems mismatch
const m4 = conv(m1, cgs);
add(m3, m4); // ok