corva-convert-units
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'Square Millimeters' | ||
, display: 'mm²' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1/1000000 | ||
, plural: 'Centimeters' | ||
, display: 'cm²' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1/10000 | ||
, plural: 'Square Meters' | ||
, display: 'm²' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1 | ||
, plural: 'Hectares' | ||
, display: 'ha' | ||
} | ||
@@ -41,2 +45,3 @@ , to_anchor: 10000 | ||
, plural: 'Square Kilometers' | ||
, display: 'km²' | ||
} | ||
@@ -52,2 +57,3 @@ , to_anchor: 1000000 | ||
, plural: 'Square Inches' | ||
, display: 'in²' | ||
} | ||
@@ -59,3 +65,4 @@ , to_anchor: 1/144 | ||
singular: 'Square Yard' | ||
, plural: 'Square Yards' | ||
, plural: 'Square Yards' | ||
, display: 'yd²' | ||
} | ||
@@ -68,2 +75,3 @@ , to_anchor: 9 | ||
, plural: 'Square Feet' | ||
, display: 'ft²' | ||
} | ||
@@ -76,2 +84,3 @@ , to_anchor: 1 | ||
, plural: 'Acres' | ||
, display: 'ac' | ||
} | ||
@@ -84,2 +93,3 @@ , to_anchor: 43560 | ||
, plural: 'Square Miles' | ||
, display: 'mi²' | ||
} | ||
@@ -86,0 +96,0 @@ , to_anchor: 27878400 |
@@ -9,2 +9,3 @@ var bits | ||
, plural: 'Bits' | ||
, display: 'b' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1 | ||
, plural: 'Kilobits' | ||
, display: 'Kb' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1024 | ||
, plural: 'Megabits' | ||
, display: 'Mb' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1048576 | ||
, plural: 'Gigabits' | ||
, display: 'Gb' | ||
} | ||
@@ -41,2 +45,3 @@ , to_anchor: 1073741824 | ||
, plural: 'Terabits' | ||
, display: 'Tb' | ||
} | ||
@@ -52,2 +57,3 @@ , to_anchor: 1099511627776 | ||
, plural: 'Bytes' | ||
, display: 'B' | ||
} | ||
@@ -60,2 +66,3 @@ , to_anchor: 1 | ||
, plural: 'Kilobytes' | ||
, display: 'KB' | ||
} | ||
@@ -68,2 +75,3 @@ , to_anchor: 1024 | ||
, plural: 'Megabytes' | ||
, display: 'MB' | ||
} | ||
@@ -76,2 +84,3 @@ , to_anchor: 1048576 | ||
, plural: 'Gigabytes' | ||
, display: 'GB' | ||
} | ||
@@ -84,2 +93,3 @@ , to_anchor: 1073741824 | ||
, plural: 'Terabytes' | ||
, display: 'TB' | ||
} | ||
@@ -86,0 +96,0 @@ , to_anchor: 1099511627776 |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'Each' | ||
, display: 'Each' | ||
} | ||
@@ -11,0 +12,0 @@ , to_anchor: 1 |
@@ -8,3 +8,4 @@ var metric | ||
singular: 'Newton Meter' | ||
, plural: 'Newton Meters' | ||
, plural: 'Newton Meters' | ||
, display: 'Nm' | ||
} | ||
@@ -16,3 +17,4 @@ , to_anchor: 1 | ||
singular: 'Joule' | ||
, plural: 'Joules' | ||
, plural: 'Joules' | ||
, display: 'J' | ||
} | ||
@@ -27,3 +29,4 @@ , to_anchor: 1 | ||
singular: 'Pound Foot' | ||
, plural: 'Pound Feet' | ||
, plural: 'Pound Feet' | ||
, display: 'ft-lb' | ||
} | ||
@@ -30,0 +33,0 @@ , to_anchor: 1 |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'Millimeters' | ||
, display: 'mm' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1/1000 | ||
, plural: 'Centimeters' | ||
, display: 'cm' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1/100 | ||
, plural: 'Meters' | ||
, display: 'm' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1 | ||
, plural: 'Kilometers' | ||
, display: 'km' | ||
} | ||
@@ -44,2 +48,3 @@ , to_anchor: 1000 | ||
, plural: 'Inches' | ||
, display: 'in' | ||
} | ||
@@ -51,3 +56,4 @@ , to_anchor: 1/12 | ||
singular: 'Yard' | ||
, plural: 'Yards' | ||
, plural: 'Yards' | ||
, display: 'yd' | ||
} | ||
@@ -60,2 +66,3 @@ , to_anchor: 3 | ||
, plural: 'Feet' | ||
, display: 'ft' | ||
} | ||
@@ -68,2 +75,3 @@ , to_anchor: 1 | ||
, plural: 'Miles' | ||
, display: 'mi' | ||
} | ||
@@ -70,0 +78,0 @@ , to_anchor: 5280 |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'Micrograms' | ||
, display: 'mcg' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1/1000000 | ||
, plural: 'Milligrams' | ||
, display: 'mg' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1/1000 | ||
, plural: 'Grams' | ||
, display: 'g' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1 | ||
, plural: 'Kilograms' | ||
, display: 'kg' | ||
} | ||
@@ -44,2 +48,3 @@ , to_anchor: 1000 | ||
, plural: 'Ounces' | ||
, display: 'oz' | ||
} | ||
@@ -52,2 +57,3 @@ , to_anchor: 1/16 | ||
, plural: 'Pounds' | ||
, display: 'lb' | ||
} | ||
@@ -54,0 +60,0 @@ , to_anchor: 1 |
@@ -8,3 +8,4 @@ var metric | ||
singular: 'Part-per Million' | ||
, plural: 'Parts-per Million' | ||
, plural: 'Parts-per Million' | ||
, display: 'ppm' | ||
} | ||
@@ -16,3 +17,4 @@ , to_anchor: 1 | ||
singular: 'Part-per Billion' | ||
, plural: 'Parts-per Billion' | ||
, plural: 'Parts-per Billion' | ||
, display: 'ppb' | ||
} | ||
@@ -24,3 +26,4 @@ , to_anchor: .001 | ||
singular: 'Part-per Trillion' | ||
, plural: 'Parts-per Trillion' | ||
, plural: 'Parts-per Trillion' | ||
, display: 'ppt' | ||
} | ||
@@ -32,3 +35,4 @@ , to_anchor: .000001 | ||
singular: 'Part-per Quadrillion' | ||
, plural: 'Parts-per Quadrillion' | ||
, plural: 'Parts-per Quadrillion' | ||
, display: 'ppq' | ||
} | ||
@@ -35,0 +39,0 @@ , to_anchor: .000000001 |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'pascals' | ||
, display: 'Pa' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1/1000 | ||
, plural: 'kilopascals' | ||
, display: 'kPa' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1 | ||
, plural: 'megapascals' | ||
, display: 'MPa' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1000 | ||
, plural: 'hectopascals' | ||
, display: 'hPa' | ||
} | ||
@@ -41,2 +45,3 @@ , to_anchor: 1/10 | ||
, plural: 'bar' | ||
, display: 'bar' | ||
} | ||
@@ -49,2 +54,3 @@ , to_anchor: 100 | ||
, plural: 'torr' | ||
, display: 'torr' | ||
} | ||
@@ -60,2 +66,3 @@ , to_anchor: 101325/760000 | ||
, plural: 'pounds per square inch' | ||
, display: 'psi' | ||
} | ||
@@ -68,2 +75,3 @@ , to_anchor: 1/1000 | ||
, plural: 'kilopounds per square inch' | ||
, display: 'ksi' | ||
} | ||
@@ -76,2 +84,3 @@ , to_anchor: 1 | ||
, plural: 'pounds per square foot' | ||
, display: 'lbf/ft²' | ||
} | ||
@@ -84,2 +93,3 @@ , to_anchor: (1/144)/1000 | ||
, plural: 'decipounds per square foot' | ||
, display: 'lbf/(100·ft²)' | ||
} | ||
@@ -86,0 +96,0 @@ , to_anchor: ((1/144)/10) |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'Metres per second' | ||
, display: 'm/s' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 3.6 | ||
, plural: 'Kilometres per hour' | ||
, display: 'kph' | ||
} | ||
@@ -28,2 +30,3 @@ , to_anchor: 1 | ||
, plural: 'Miles per hour' | ||
, display: 'mph' | ||
} | ||
@@ -36,2 +39,3 @@ , to_anchor: 1 | ||
, plural: 'Knots' | ||
, display: 'knot' | ||
} | ||
@@ -44,2 +48,3 @@ , to_anchor: 1.150779 | ||
, plural: 'Feet per second' | ||
, display: 'ft/s' | ||
} | ||
@@ -46,0 +51,0 @@ , to_anchor: 0.681818 |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'degrees Celsius' | ||
, display: '°C' | ||
} | ||
@@ -18,2 +19,3 @@ , to_anchor: 1 | ||
, plural: 'degrees Kelvin' | ||
, display: '°K' | ||
} | ||
@@ -30,2 +32,3 @@ , to_anchor: 1 | ||
, plural: 'degrees Fahrenheit' | ||
, display: '°F' | ||
} | ||
@@ -32,0 +35,0 @@ , to_anchor: 1 |
@@ -9,2 +9,3 @@ var time; | ||
, plural: 'Nanoseconds' | ||
, display: 'ns' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1/1000000000 | ||
, plural: 'Microseconds' | ||
, display: 'mu' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1/1000000 | ||
, plural: 'Milliseconds' | ||
, display: 'ms' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1/1000 | ||
, plural: 'Seconds' | ||
, display: 's' | ||
} | ||
@@ -41,2 +45,3 @@ , to_anchor: 1 | ||
, plural: 'Minutes' | ||
, display: 'min' | ||
} | ||
@@ -49,2 +54,3 @@ , to_anchor: 60 | ||
, plural: 'Hours' | ||
, display: 'hr' | ||
} | ||
@@ -57,2 +63,3 @@ , to_anchor: 60 * 60 | ||
, plural: 'Days' | ||
, display: 'd' | ||
} | ||
@@ -65,2 +72,3 @@ , to_anchor: 60 * 60 * 24 | ||
, plural: 'Weeks' | ||
, display: 'w' | ||
} | ||
@@ -73,2 +81,3 @@ , to_anchor: 60 * 60 * 24 * 7 | ||
, plural: 'Months' | ||
, display: 'm' | ||
} | ||
@@ -81,2 +90,3 @@ , to_anchor: 60 * 60 * 24 * daysInYear / 12 | ||
, plural: 'Years' | ||
, display: 'yr' | ||
} | ||
@@ -83,0 +93,0 @@ , to_anchor: 60 * 60 * 24 * daysInYear |
@@ -9,2 +9,3 @@ var metric | ||
, plural: 'Cubic Millimeters' | ||
, display: 'mm³' | ||
} | ||
@@ -17,2 +18,3 @@ , to_anchor: 1/1000000 | ||
, plural: 'Cubic Centimeters' | ||
, display: 'cm³' | ||
} | ||
@@ -25,2 +27,3 @@ , to_anchor: 1/1000 | ||
, plural: 'Millilitres' | ||
, display: 'ml' | ||
} | ||
@@ -33,2 +36,3 @@ , to_anchor: 1/1000 | ||
, plural: 'Centilitres' | ||
, display: 'cl' | ||
} | ||
@@ -41,2 +45,3 @@ , to_anchor: 1/100 | ||
, plural: 'Decilitres' | ||
, display: 'dl' | ||
} | ||
@@ -49,2 +54,3 @@ , to_anchor: 1/10 | ||
, plural: 'Litres' | ||
, display: 'l' | ||
} | ||
@@ -57,2 +63,3 @@ , to_anchor: 1 | ||
, plural: 'Cubic meters' | ||
, display: 'm³' | ||
} | ||
@@ -65,2 +72,3 @@ , to_anchor: 1000 | ||
, plural: 'Cubic kilometers' | ||
, display: 'km³' | ||
} | ||
@@ -74,3 +82,4 @@ , to_anchor: 1000000000000 | ||
singular: 'Matsked' | ||
, plural: 'Matskedar' | ||
, plural: 'Matskedar' | ||
, display: 'krm' | ||
} | ||
@@ -83,2 +92,3 @@ , to_anchor: 1/1000 | ||
, plural: 'Teskedar' | ||
, display: 'tsk' | ||
} | ||
@@ -90,3 +100,4 @@ , to_anchor: 5/1000 | ||
singular: 'Matsked' | ||
, plural: 'Matskedar' | ||
, plural: 'Matskedar' | ||
, display: 'msk' | ||
} | ||
@@ -98,3 +109,4 @@ , to_anchor: 15/1000 | ||
singular: 'Kaffekopp' | ||
, plural: 'Kaffekoppar' | ||
, plural: 'Kaffekoppar' | ||
, display: 'kkp' | ||
} | ||
@@ -106,3 +118,4 @@ , to_anchor: 150/1000 | ||
singular: 'Glas' | ||
, plural: 'Glas' | ||
, plural: 'Glas' | ||
, display: 'glas' | ||
} | ||
@@ -115,2 +128,3 @@ , to_anchor: 200/1000 | ||
, plural: 'Kannor' | ||
, display: 'kanna' | ||
} | ||
@@ -126,2 +140,3 @@ , to_anchor: 2.617 | ||
, plural: 'Teaspoons' | ||
, display: 'tsp' | ||
} | ||
@@ -134,2 +149,3 @@ , to_anchor: 1/6 | ||
, plural: 'Tablespoons' | ||
, display: 'tbsp' | ||
} | ||
@@ -142,2 +158,3 @@ , to_anchor: 1/2 | ||
, plural: 'Cubic inches' | ||
, display: 'in³' | ||
} | ||
@@ -150,2 +167,3 @@ , to_anchor: 0.55411 | ||
, plural: 'Fluid Ounces' | ||
, display: 'fl-oz' | ||
} | ||
@@ -158,2 +176,3 @@ , to_anchor: 1 | ||
, plural: 'Cups' | ||
, display: 'cup' | ||
} | ||
@@ -166,2 +185,3 @@ , to_anchor: 8 | ||
, plural: 'Pints' | ||
, display: 'pint' | ||
} | ||
@@ -174,2 +194,3 @@ , to_anchor: 16 | ||
, plural: 'Quarts' | ||
, display: 'qt' | ||
} | ||
@@ -182,2 +203,3 @@ , to_anchor: 32 | ||
, plural: 'Gallons' | ||
, display: 'g' | ||
} | ||
@@ -190,2 +212,3 @@ , to_anchor: 128 | ||
, plural: 'Cubic feet' | ||
, display: 'ft³' | ||
} | ||
@@ -198,2 +221,3 @@ , to_anchor: 957.506 | ||
, plural: 'Cubic yards' | ||
, display: 'yd³' | ||
} | ||
@@ -205,3 +229,4 @@ , to_anchor: 25852.7 | ||
singular: 'Oil barrel' | ||
, plural: 'Oil barrels' | ||
, plural: 'Oil barrels' | ||
, display: 'bbl' | ||
} | ||
@@ -208,0 +233,0 @@ , to_anchor: 5376 |
@@ -133,6 +133,7 @@ var convert | ||
best = { | ||
val: result, | ||
unit: possibility, | ||
singular: unit.singular, | ||
plural: unit.plural | ||
val: result | ||
, unit: possibility | ||
, singular: unit.singular | ||
, plural: unit.plural | ||
, display: unit.display | ||
}; | ||
@@ -144,3 +145,3 @@ } | ||
return best; | ||
} | ||
}; | ||
@@ -155,7 +156,7 @@ /** | ||
each(systems, function (units, system) { | ||
if(system == '_anchors') | ||
if(system === '_anchors') | ||
return false; | ||
each(units, function (unit, testAbbr) { | ||
if(testAbbr == abbr) { | ||
if(testAbbr === abbr) { | ||
found = { | ||
@@ -189,4 +190,5 @@ abbr: abbr | ||
, plural: resp.unit.name.plural | ||
, display: resp.unit.name.display | ||
}; | ||
} | ||
}; | ||
@@ -193,0 +195,0 @@ /** |
{ | ||
"name": "corva-convert-units", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Convert between quantities in different units", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
119
README.md
convert-units | ||
============= | ||
[![Build Status](https://travis-ci.org/ben-ng/convert-units.png)](https://travis-ci.org/ben-ng/convert-units) [![Downloads](https://img.shields.io/npm/dm/convert-units.svg)](https://www.npmjs.com/package/convert-units) | ||
A handy utility for converting between quantities in different units. | ||
Usage | ||
----- | ||
`convert-units` has a simple chained API that is easy to read. | ||
Here's how you move between the metric units for volume: | ||
```js | ||
var convert = require('convert-units') | ||
convert(1).from('l').to('ml') | ||
// 1000 | ||
``` | ||
Jump from imperial to metric units the same way: | ||
```js | ||
convert(1).from('lb').to('kg') | ||
// 0.4536... (tested to 4 significant figures) | ||
``` | ||
Just be careful not to ask for an impossible conversion: | ||
```js | ||
convert(1).from('oz').to('fl-oz') | ||
// throws -- you can't go from mass to volume! | ||
``` | ||
You can ask `convert-units` to select the best unit for you with optional exclusions: | ||
```js | ||
convert(1200).from('mm').toBest() | ||
// 1.2 Meters (the smallest unit with a value above 1) | ||
convert(1200).from('mm').toBest({exclude: ['m']}) | ||
// 120 Centimeters (the smallest unit excluding meters) | ||
``` | ||
You can get a list of the measurement types supported with `.measures` | ||
```js | ||
convert().measures() | ||
// [ 'length', 'mass', 'volume' ] | ||
``` | ||
If you ever want to know the possible conversions for a unit, just use `.possibilities` | ||
```js | ||
convert().from('l').possibilities() | ||
// [ 'ml', 'l', 'tsp', 'tbsp', 'fl-oz', 'cup', 'pnt', 'qt', 'gal' ] | ||
convert().from('kg').possibilities() | ||
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ] | ||
``` | ||
You can also get the possible conversions for a measure: | ||
```js | ||
convert().possibilities('mass') | ||
// [ 'mcg', 'mg', 'g', 'kg', 'oz', 'lb' ] | ||
``` | ||
You can also get the all the available units: | ||
```js | ||
convert().possibilities() | ||
// [ 'mm', 'cm', 'm', 'in', 'ft', 'mi', 'mcg', 'mg', 'g', 'kg', 'oz', 'lb', 'ml', 'l', 'tsp', 'Tbs', 'fl-oz', 'cup', 'pnt', 'qt', 'gal', 'ea' ]; | ||
``` | ||
To get a detailed description of a unit, use `describe` | ||
```js | ||
convert().describe('kg') | ||
/* | ||
{ | ||
abbr: 'kg' | ||
, measure: 'mass' | ||
, system: 'metric' | ||
, singular: 'Kilogram' | ||
, plural: 'Kilograms' | ||
} | ||
*/ | ||
``` | ||
To get detailed descriptions of all units, use `list`. | ||
```js | ||
convert().list() | ||
/* | ||
[{ | ||
abbr: 'kg' | ||
, measure: 'mass' | ||
, system: 'metric' | ||
, singular: 'Kilogram' | ||
, plural: 'Kilograms' | ||
}, ...] | ||
*/ | ||
``` | ||
You can also get detailed descriptions of all units for a measure: | ||
```js | ||
convert().list('mass') | ||
/* | ||
[{ | ||
abbr: 'kg' | ||
, measure: 'mass' | ||
, system: 'metric' | ||
, singular: 'Kilogram' | ||
, plural: 'Kilograms' | ||
}, ...] | ||
*/ | ||
``` | ||
### Want More? | ||
Adding new measurement sets is easy. Take a look at [`lib/definitions`](https://github.com/ben-ng/convert-units/tree/master/lib/definitions) to see how it's done. | ||
### Fork/Duplication Information | ||
@@ -130,3 +13,3 @@ | ||
------- | ||
Copyright (c) 2013-2017 Corva <corva.ai>, Ben Ng, and Contributors, http://benng.me | ||
Copyright (c) 2013-2017 Corva http://corva.ai ; Ben Ng, and Contributors, http://benng.me | ||
@@ -133,0 +16,0 @@ Permission is hereby granted, free of charge, to any person |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1223
25027
35