Reputation: 33439
Is there are reputable and comprehensive unit conversion Javascript library? I do not want any libraries that makes AJAX calls to WolframAlpha or Google but something that does the calculation locally.
Upvotes: 0
Views: 4887
Reputation: 6819
The math.js library comes with support for units. The library does not yet support derived units but that is on the planning.
Example usage:
math.evaluate('2 inch in cm');
math.evaluate('0.5kg + 33g');
math.evaluate('cos(45 deg)');
Upvotes: 5
Reputation: 572
The library "measure" converts between unit types (volume, mass, etc.) and supports multiple unit systems (US, Imperial, Metric)
// volume
measure('1 teaspoon').teaspoons() // 1
measure('1 1/2 tsp.').teaspoons() // 1.5
measure('2 cups and 1 pint').quarts() // 1
// mass
measure('1 pound').ounces() // 16
measure('1 1/2 oz.').ounces() // 1.5
// operations
measure('1 teaspoon').add('1 teaspoon').teaspoons();
measure('6 1/2 teaspoon').divide(2).teaspoons(); // 3.25
https://github.com/dubbs/measure
Upvotes: 2