1.0.8 • Published 7 years ago

tinu v1.0.8

Weekly downloads
22
License
MIT
Repository
github
Last release
7 years ago

TINU - These Incredibly Naughty Units

NPM version Build Status

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.distance(12);           // → {value: 12, unit: "cm", ...}
Tinu.distance(12, "mm");     // → {value: 12, unit: "mm", ...}
Tinu.distance(12, "in");     // → {value: 12, unit: "in", ...}
Tinu.distance("12m");        // → {value: 12, unit: "m",  ...}
Tinu.distance("12 m");       // → {value: 12, unit: "m",  ...}
Tinu.distance("12.00m");     // → {value: 12, unit: "m",  ...}

Tinu.area(80, "m2");         // → {value: 80, unit: "m2", ...}

The .to() method converts to the same object but in the requested unit.

Tinu.distance(12).to("m");            // → {value: 0.012, "m", ...}
Tinu.distance(12).to("m").to("mm");   // → {value: 120, "mm", ...}
Tinu.distance(12).to();  // → converts to the default target unit: {value: 0.012, "m", ...}

The .toNumber(unit=null) method converts to a Number in the requested unit

Tinu.distance(12).toNumber("m");  // → 0.012
Tinu.distance(12).toNumber();     // → 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.distance(12, "cm").toString("m");     // → "0.012 m"
Tinu.distance(12, "cm").toString("m", 2);  // → "0.01 m"
Tinu.distance(12, "cm").toString();        // → converts to the default target unit: "0.012 m"

Please help yourself to add type and other unit if needed !

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago