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.eval('2 inch in cm');
math.eval('0.5kg + 33g');
math.eval('cos(45 deg)');
Pregunta
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.
Solución
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.eval('2 inch in cm');
math.eval('0.5kg + 33g');
math.eval('cos(45 deg)');
Otros consejos
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