TINU - These Incredibly Naughty Units
A toolkit to convert easily any units.
Usage
Add the npm package tinu to your project:
npm install tinu --save
or clone:
git clone git@github.com:wanadev/tinu.git
Getting Started
Conversion function returns an object that contain the parsed and NORMALIZED value/unit AND some function described bellow :
Tinu; // → {value: 12, unit: "cm", ...}Tinu; // → {value: 12, unit: "mm", ...}Tinu; // → {value: 12, unit: "in", ...}Tinu; // → {value: 12, unit: "m", ...}Tinu; // → {value: 12, unit: "m", ...}Tinu; // → {value: 12, unit: "m", ...} Tinu; // → {value: 80, unit: "m2", ...}
The .to() method converts to the same object but in the requested unit.
Tinu; // → {value: 0.012, "m", ...}Tinu; // → {value: 120, "mm", ...}Tinu; // → converts to the default target unit: {value: 0.012, "m", ...}
The .toNumber(unit=null) method converts to a Number in the requested unit
Tinu; // → 0.012Tinu; // → converts to the default target unit: 0.012
The .toString(unit=null, numericScale=null) method converts to a String in the requested unit, that includes the unit
Tinu; // → "0.012 m"Tinu; // → "0.01 m"Tinu; // → converts to the default target unit: "0.012 m"
Please help yourself to add type and other unit if needed !