Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

corva-convert-units

Package Overview
Dependencies
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

corva-convert-units - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

lib/definitions/density.js

153

lib/definitions/area.js

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,39 +6,39 @@ metric = {

name: {
singular: 'Square Millimeter'
, plural: 'Square Millimeters'
, display: 'mm²'
}
, to_anchor: 1/1000000
}
, cm2: {
singular: 'Square Millimeter',
plural: 'Square Millimeters',
display: 'mm²'
},
to_anchor: 1 / 1000000
},
cm2: {
name: {
singular: 'Centimeter'
, plural: 'Centimeters'
, display: 'cm²'
}
, to_anchor: 1/10000
}
, m2: {
singular: 'Centimeter',
plural: 'Centimeters',
display: 'cm²'
},
to_anchor: 1 / 10000
},
m2: {
name: {
singular: 'Square Meter'
, plural: 'Square Meters'
, display: 'm²'
}
, to_anchor: 1
}
, ha: {
singular: 'Square Meter',
plural: 'Square Meters',
display: 'm²'
},
to_anchor: 1
},
ha: {
name: {
singular: 'Hectare'
, plural: 'Hectares'
, display: 'ha'
}
, to_anchor: 10000
}
, km2: {
singular: 'Hectare',
plural: 'Hectares',
display: 'ha'
},
to_anchor: 10000
},
km2: {
name: {
singular: 'Square Kilometer'
, plural: 'Square Kilometers'
, display: 'km²'
}
, to_anchor: 1000000
singular: 'Square Kilometer',
plural: 'Square Kilometers',
display: 'km²'
},
to_anchor: 1000000
}

@@ -51,39 +50,39 @@ };

name: {
singular: 'Square Inch'
, plural: 'Square Inches'
, display: 'in²'
}
, to_anchor: 1/144
}
, yd2: {
singular: 'Square Inch',
plural: 'Square Inches',
display: 'in²'
},
to_anchor: 1 / 144
},
yd2: {
name: {
singular: 'Square Yard'
, plural: 'Square Yards'
, display: 'yd²'
}
, to_anchor: 9
}
, ft2: {
singular: 'Square Yard',
plural: 'Square Yards',
display: 'yd²'
},
to_anchor: 9
},
ft2: {
name: {
singular: 'Square Foot'
, plural: 'Square Feet'
, display: 'ft²'
}
, to_anchor: 1
}
, ac: {
singular: 'Square Foot',
plural: 'Square Feet',
display: 'ft²'
},
to_anchor: 1
},
ac: {
name: {
singular: 'Acre'
, plural: 'Acres'
, display: 'ac'
}
, to_anchor: 43560
}
, mi2: {
singular: 'Acre',
plural: 'Acres',
display: 'ac'
},
to_anchor: 43560
},
mi2: {
name: {
singular: 'Square Mile'
, plural: 'Square Miles'
, display: 'mi²'
}
, to_anchor: 27878400
singular: 'Square Mile',
plural: 'Square Miles',
display: 'mi²'
},
to_anchor: 27878400
}

@@ -93,14 +92,14 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'm2'
, ratio: 10.7639
unit: 'm2',
ratio: 10.7639
},
imperial: {
unit: 'ft2',
ratio: 1 / 10.7639
}
, imperial: {
unit: 'ft2'
, ratio: 1/10.7639
}
}
};

@@ -1,3 +0,2 @@

var bits
, bytes;
var bits, bytes;

@@ -7,39 +6,39 @@ bits = {

name: {
singular: 'Bit'
, plural: 'Bits'
, display: 'b'
}
, to_anchor: 1
}
, Kb: {
singular: 'Bit',
plural: 'Bits',
display: 'b'
},
to_anchor: 1
},
Kb: {
name: {
singular: 'Kilobit'
, plural: 'Kilobits'
, display: 'Kb'
}
, to_anchor: 1024
}
, Mb: {
singular: 'Kilobit',
plural: 'Kilobits',
display: 'Kb'
},
to_anchor: 1024
},
Mb: {
name: {
singular: 'Megabit'
, plural: 'Megabits'
, display: 'Mb'
}
, to_anchor: 1048576
}
, Gb: {
singular: 'Megabit',
plural: 'Megabits',
display: 'Mb'
},
to_anchor: 1048576
},
Gb: {
name: {
singular: 'Gigabit'
, plural: 'Gigabits'
, display: 'Gb'
}
, to_anchor: 1073741824
}
, Tb: {
singular: 'Gigabit',
plural: 'Gigabits',
display: 'Gb'
},
to_anchor: 1073741824
},
Tb: {
name: {
singular: 'Terabit'
, plural: 'Terabits'
, display: 'Tb'
}
, to_anchor: 1099511627776
singular: 'Terabit',
plural: 'Terabits',
display: 'Tb'
},
to_anchor: 1099511627776
}

@@ -51,39 +50,39 @@ };

name: {
singular: 'Byte'
, plural: 'Bytes'
, display: 'B'
}
, to_anchor: 1
}
, KB: {
singular: 'Byte',
plural: 'Bytes',
display: 'B'
},
to_anchor: 1
},
KB: {
name: {
singular: 'Kilobyte'
, plural: 'Kilobytes'
, display: 'KB'
}
, to_anchor: 1024
}
, MB: {
singular: 'Kilobyte',
plural: 'Kilobytes',
display: 'KB'
},
to_anchor: 1024
},
MB: {
name: {
singular: 'Megabyte'
, plural: 'Megabytes'
, display: 'MB'
}
, to_anchor: 1048576
}
, GB: {
singular: 'Megabyte',
plural: 'Megabytes',
display: 'MB'
},
to_anchor: 1048576
},
GB: {
name: {
singular: 'Gigabyte'
, plural: 'Gigabytes'
, display: 'GB'
}
, to_anchor: 1073741824
}
, TB: {
singular: 'Gigabyte',
plural: 'Gigabytes',
display: 'GB'
},
to_anchor: 1073741824
},
TB: {
name: {
singular: 'Terabyte'
, plural: 'Terabytes'
, display: 'TB'
}
, to_anchor: 1099511627776
singular: 'Terabyte',
plural: 'Terabytes',
display: 'TB'
},
to_anchor: 1099511627776
}

@@ -93,14 +92,14 @@ };

module.exports = {
bits: bits
, bytes: bytes
, _anchors: {
bits: bits,
bytes: bytes,
_anchors: {
bits: {
unit: 'b'
, ratio: 1/8
unit: 'b',
ratio: 1 / 8
},
bytes: {
unit: 'B',
ratio: 8
}
, bytes: {
unit: 'B'
, ratio: 8
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,7 +6,7 @@ metric = {

name: {
singular: 'Each'
, plural: 'Each'
, display: 'Each'
}
, to_anchor: 1
singular: 'Each',
plural: 'Each',
display: 'Each'
},
to_anchor: 1
}

@@ -17,10 +16,10 @@ };

module.exports = {
metric: metric
, imperial: {}
, _anchors: {
metric: metric,
imperial: {},
_anchors: {
metric: {
unit: 'ea'
, ratio: 1
unit: 'ea',
ratio: 1
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,15 +6,15 @@ metric = {

name: {
singular: 'Newton Meter'
, plural: 'Newton Meters'
, display: 'Nm'
}
, to_anchor: 1
}
, J: {
singular: 'Newton Meter',
plural: 'Newton Meters',
display: 'Nm'
},
to_anchor: 1
},
J: {
name: {
singular: 'Joule'
, plural: 'Joules'
, display: 'J'
}
, to_anchor: 1
singular: 'Joule',
plural: 'Joules',
display: 'J'
},
to_anchor: 1
}

@@ -27,7 +26,7 @@ };

name: {
singular: 'Pound Foot'
, plural: 'Pound Feet'
, display: 'ft-lb'
}
, to_anchor: 1
singular: 'Pound Foot',
plural: 'Pound Feet',
display: 'ft-lb'
},
to_anchor: 1
}

@@ -37,14 +36,14 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'nm'
, ratio: 1.35581794833
unit: 'nm',
ratio: 1.35581794833
},
imperial: {
unit: 'lbf',
ratio: 1 / 1.35581794833
}
, imperial: {
unit: 'lbf'
, ratio: 1/1.35581794833
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,31 +6,31 @@ metric = {

name: {
singular: 'Millimeter'
, plural: 'Millimeters'
, display: 'mm'
}
, to_anchor: 1/1000
}
, cm: {
singular: 'Millimeter',
plural: 'Millimeters',
display: 'mm'
},
to_anchor: 1 / 1000
},
cm: {
name: {
singular: 'Centimeter'
, plural: 'Centimeters'
, display: 'cm'
}
, to_anchor: 1/100
}
, m: {
singular: 'Centimeter',
plural: 'Centimeters',
display: 'cm'
},
to_anchor: 1 / 100
},
m: {
name: {
singular: 'Meter'
, plural: 'Meters'
, display: 'm'
}
, to_anchor: 1
}
, km: {
singular: 'Meter',
plural: 'Meters',
display: 'm'
},
to_anchor: 1
},
km: {
name: {
singular: 'Kilometer'
, plural: 'Kilometers'
, display: 'km'
}
, to_anchor: 1000
singular: 'Kilometer',
plural: 'Kilometers',
display: 'km'
},
to_anchor: 1000
}

@@ -43,31 +42,31 @@ };

name: {
singular: 'Inch'
, plural: 'Inches'
, display: 'in'
}
, to_anchor: 1/12
}
, yd: {
singular: 'Inch',
plural: 'Inches',
display: 'in'
},
to_anchor: 1 / 12
},
yd: {
name: {
singular: 'Yard'
, plural: 'Yards'
, display: 'yd'
}
, to_anchor: 3
}
, ft: {
singular: 'Yard',
plural: 'Yards',
display: 'yd'
},
to_anchor: 3
},
ft: {
name: {
singular: 'Foot'
, plural: 'Feet'
, display: 'ft'
}
, to_anchor: 1
}
, mi: {
singular: 'Foot',
plural: 'Feet',
display: 'ft'
},
to_anchor: 1
},
mi: {
name: {
singular: 'Mile'
, plural: 'Miles'
, display: 'mi'
}
, to_anchor: 5280
singular: 'Mile',
plural: 'Miles',
display: 'mi'
},
to_anchor: 5280
}

@@ -77,14 +76,14 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'm'
, ratio: 3.281
unit: 'm',
ratio: 3.281
},
imperial: {
unit: 'ft',
ratio: 1 / 3.281
}
, imperial: {
unit: 'ft'
, ratio: 1/3.281
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,31 +6,31 @@ metric = {

name: {
singular: 'Microgram'
, plural: 'Micrograms'
, display: 'mcg'
}
, to_anchor: 1/1000000
}
, mg: {
singular: 'Microgram',
plural: 'Micrograms',
display: 'mcg'
},
to_anchor: 1 / 1000000
},
mg: {
name: {
singular: 'Milligram'
, plural: 'Milligrams'
, display: 'mg'
}
, to_anchor: 1/1000
}
, g: {
singular: 'Milligram',
plural: 'Milligrams',
display: 'mg'
},
to_anchor: 1 / 1000
},
g: {
name: {
singular: 'Gram'
, plural: 'Grams'
, display: 'g'
}
, to_anchor: 1
}
, kg: {
singular: 'Gram',
plural: 'Grams',
display: 'g'
},
to_anchor: 1
},
kg: {
name: {
singular: 'Kilogram'
, plural: 'Kilograms'
, display: 'kg'
}
, to_anchor: 1000
singular: 'Kilogram',
plural: 'Kilograms',
display: 'kg'
},
to_anchor: 1000
}

@@ -43,15 +42,15 @@ };

name: {
singular: 'Ounce'
, plural: 'Ounces'
, display: 'oz'
}
, to_anchor: 1/16
}
, lb: {
singular: 'Ounce',
plural: 'Ounces',
display: 'oz'
},
to_anchor: 1 / 16
},
lb: {
name: {
singular: 'Pound'
, plural: 'Pounds'
, display: 'lb'
}
, to_anchor: 1
singular: 'Pound',
plural: 'Pounds',
display: 'lb'
},
to_anchor: 1
}

@@ -61,14 +60,14 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'g'
, ratio: 1/453.592
unit: 'g',
ratio: 1 / 453.592
},
imperial: {
unit: 'lb',
ratio: 453.592
}
, imperial: {
unit: 'lb'
, ratio: 453.592
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,43 +6,45 @@ metric = {

name: {
singular: 'Part-per Million'
, plural: 'Parts-per Million'
, display: 'ppm'
}
, to_anchor: 1
}
, ppb: {
singular: 'Part-per Million',
plural: 'Parts-per Million',
display: 'ppm'
},
to_anchor: 1
},
ppb: {
name: {
singular: 'Part-per Billion'
, plural: 'Parts-per Billion'
, display: 'ppb'
}
, to_anchor: .001
}
, ppt: {
singular: 'Part-per Billion',
plural: 'Parts-per Billion',
display: 'ppb'
},
to_anchor: .001
},
ppt: {
name: {
singular: 'Part-per Trillion'
, plural: 'Parts-per Trillion'
, display: 'ppt'
}
, to_anchor: .000001
}
, ppq: {
singular: 'Part-per Trillion',
plural: 'Parts-per Trillion',
display: 'ppt'
},
to_anchor: .000001
},
ppq: {
name: {
singular: 'Part-per Quadrillion'
, plural: 'Parts-per Quadrillion'
, display: 'ppq'
}
, to_anchor: .000000001
singular: 'Part-per Quadrillion',
plural: 'Parts-per Quadrillion',
display: 'ppq'
},
to_anchor: .000000001
}
};
imperial = {};
module.exports = {
metric: metric
, imperial: {}
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'ppm'
, ratio: .000001
unit: 'ppm',
ratio: .000001
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,47 +6,47 @@ metric = {

name: {
singular: 'pascal'
, plural: 'pascals'
, display: 'Pa'
}
, to_anchor: 1/1000
}
, kPa: {
singular: 'pascal',
plural: 'pascals',
display: 'Pa'
},
to_anchor: 1 / 1000
},
kPa: {
name: {
singular: 'kilopascal'
, plural: 'kilopascals'
, display: 'kPa'
}
, to_anchor: 1
}
, MPa: {
singular: 'kilopascal',
plural: 'kilopascals',
display: 'kPa'
},
to_anchor: 1
},
MPa: {
name: {
singular: 'megapascal'
, plural: 'megapascals'
, display: 'MPa'
}
, to_anchor: 1000
}
, hPa: {
singular: 'megapascal',
plural: 'megapascals',
display: 'MPa'
},
to_anchor: 1000
},
hPa: {
name: {
singular: 'hectopascal'
, plural: 'hectopascals'
, display: 'hPa'
}
, to_anchor: 1/10
}
, bar: {
singular: 'hectopascal',
plural: 'hectopascals',
display: 'hPa'
},
to_anchor: 1 / 10
},
bar: {
name: {
singular: 'bar'
, plural: 'bar'
, display: 'bar'
}
, to_anchor: 100
}
, torr: {
singular: 'bar',
plural: 'bar',
display: 'bar'
},
to_anchor: 100
},
torr: {
name: {
singular: 'torr'
, plural: 'torr'
, display: 'torr'
}
, to_anchor: 101325/760000
singular: 'torr',
plural: 'torr',
display: 'torr'
},
to_anchor: 101325 / 760000
}

@@ -59,39 +58,39 @@ };

name: {
singular: 'pound per square inch'
, plural: 'pounds per square inch'
, display: 'psi'
}
, to_anchor: 1/1000
}
, ksi: {
singular: 'pound per square inch',
plural: 'pounds per square inch',
display: 'psi'
},
to_anchor: 1 / 1000
},
ksi: {
name: {
singular: 'kilopound per square inch'
, plural: 'kilopounds per square inch'
, display: 'ksi'
}
, to_anchor: 1
}
, psf: {
singular: 'kilopound per square inch',
plural: 'kilopounds per square inch',
display: 'ksi'
},
to_anchor: 1
},
psf: {
name: {
singular: 'pound per square foot'
, plural: 'pounds per square foot'
, display: 'lbf/ft²'
}
, to_anchor: (1/144)/1000
}
, dsf: {
singular: 'pound per square foot',
plural: 'pounds per square foot',
display: 'lbf/ft²'
},
to_anchor: (1 / 144) / 1000
},
dsf: {
name: {
singular: 'decapound per square foot'
, plural: 'decapound per square foot'
, display: 'lbf/(10·ft²)'
}
, to_anchor: ((1/144)/100)
}
, hsf: {
singular: 'decapound per square foot',
plural: 'decapound per square foot',
display: 'lbf/(10·ft²)'
},
to_anchor: ((1 / 144) / 100)
},
hsf: {
name: {
singular: 'hectopound per square foot'
, plural: 'hectopound per square foot'
, display: 'lbf/(100·ft²)'
}
, to_anchor: ((1/144)/10)
singular: 'hectopound per square foot',
plural: 'hectopound per square foot',
display: 'lbf/(100·ft²)'
},
to_anchor: ((1 / 144) / 10)
}

@@ -101,14 +100,14 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'kPa'
, ratio: 0.00014503768078
unit: 'kPa',
ratio: 0.00014503768078
},
imperial: {
unit: 'psi',
ratio: 1 / 0.00014503768078
}
, imperial: {
unit: 'psi'
, ratio: 1/0.00014503768078
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,58 +6,58 @@ metric = {

name: {
singular: 'Metre per second'
, plural: 'Metres per second'
, display: 'm/s'
}
, to_anchor: 3.6
singular: 'Metre per second',
plural: 'Metres per second',
display: 'm/s'
},
to_anchor: 3.6
},
'km/h': {
name: {
singular: 'Kilometre per hour',
plural: 'Kilometres per hour',
display: 'kph'
},
to_anchor: 1
}
, 'km/h': {
};
imperial = {
'm/h': {
name: {
singular: 'Kilometre per hour'
, plural: 'Kilometres per hour'
, display: 'kph'
}
, to_anchor: 1
singular: 'Mile per hour',
plural: 'Miles per hour',
display: 'mph'
},
to_anchor: 1
},
knot: {
name: {
singular: 'Knot',
plural: 'Knots',
display: 'knot'
},
to_anchor: 1.150779
},
'ft/s': {
name: {
singular: 'Foot per second',
plural: 'Feet per second',
display: 'ft/s'
},
to_anchor: 0.681818
}
}
imperial = {
'm/h': {
name: {
singular: 'Mile per hour'
, plural: 'Miles per hour'
, display: 'mph'
}
, to_anchor: 1
}
, knot: {
name: {
singular: 'Knot'
, plural: 'Knots'
, display: 'knot'
}
, to_anchor: 1.150779
}
, 'ft/s': {
name: {
singular: 'Foot per second'
, plural: 'Feet per second'
, display: 'ft/s'
}
, to_anchor: 0.681818
}
};
module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'km/h'
, ratio: 1/1.609344
unit: 'km/h',
ratio: 1 / 1.609344
},
imperial: {
unit: 'm/h',
ratio: 1.609344
}
, imperial: {
unit: 'm/h'
, ratio: 1.609344
}
}
};

@@ -1,3 +0,2 @@

var metric
, imperial;
var metric, imperial;

@@ -7,17 +6,17 @@ metric = {

name: {
singular: 'degree Celsius'
, plural: 'degrees Celsius'
, display: '°C'
}
, to_anchor: 1
, anchor_shift: 0
singular: 'degree Celsius',
plural: 'degrees Celsius',
display: '°C'
},
to_anchor: 1,
anchor_shift: 0
},
K: {
name: {
singular: 'degree Kelvin'
, plural: 'degrees Kelvin'
, display: '°K'
}
, to_anchor: 1
, anchor_shift: 273.15
singular: 'degree Kelvin',
plural: 'degrees Kelvin',
display: '°K'
},
to_anchor: 1,
anchor_shift: 273.15
}

@@ -29,7 +28,7 @@ };

name: {
singular: 'degree Fahrenheit'
, plural: 'degrees Fahrenheit'
, display: '°F'
}
, to_anchor: 1
singular: 'degree Fahrenheit',
plural: 'degrees Fahrenheit',
display: '°F'
},
to_anchor: 1
}

@@ -39,15 +38,18 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'C'
, transform: function (C) { return C / (5/9) + 32 }
unit: 'C',
transform: function(C) {
return C / (5 / 9) + 32
}
},
imperial: {
unit: 'F',
transform: function(F) {
return (F - 32) * (5 / 9)
}
}
, imperial: {
unit: 'F'
, transform: function (F) { return (F - 32) * (5/9) }
}
}
};

@@ -7,79 +7,79 @@ var time;

name: {
singular: 'Nanosecond'
, plural: 'Nanoseconds'
, display: 'ns'
}
, to_anchor: 1/1000000000
}
, mu: {
singular: 'Nanosecond',
plural: 'Nanoseconds',
display: 'ns'
},
to_anchor: 1 / 1000000000
},
mu: {
name: {
singular: 'Microsecond'
, plural: 'Microseconds'
, display: 'mu'
}
, to_anchor: 1/1000000
}
, ms: {
singular: 'Microsecond',
plural: 'Microseconds',
display: 'mu'
},
to_anchor: 1 / 1000000
},
ms: {
name: {
singular: 'Millisecond'
, plural: 'Milliseconds'
, display: 'ms'
}
, to_anchor: 1/1000
}
, s: {
singular: 'Millisecond',
plural: 'Milliseconds',
display: 'ms'
},
to_anchor: 1 / 1000
},
s: {
name: {
singular: 'Second'
, plural: 'Seconds'
, display: 's'
}
, to_anchor: 1
}
, min: {
singular: 'Second',
plural: 'Seconds',
display: 's'
},
to_anchor: 1
},
min: {
name: {
singular: 'Minute'
, plural: 'Minutes'
, display: 'min'
}
, to_anchor: 60
}
, h: {
singular: 'Minute',
plural: 'Minutes',
display: 'min'
},
to_anchor: 60
},
h: {
name: {
singular: 'Hour'
, plural: 'Hours'
, display: 'hr'
}
, to_anchor: 60 * 60
}
, d: {
singular: 'Hour',
plural: 'Hours',
display: 'hr'
},
to_anchor: 60 * 60
},
d: {
name: {
singular: 'Day'
, plural: 'Days'
, display: 'd'
}
, to_anchor: 60 * 60 * 24
}
, week: {
singular: 'Day',
plural: 'Days',
display: 'd'
},
to_anchor: 60 * 60 * 24
},
week: {
name: {
singular: 'Week'
, plural: 'Weeks'
, display: 'w'
}
, to_anchor: 60 * 60 * 24 * 7
}
, month: {
singular: 'Week',
plural: 'Weeks',
display: 'w'
},
to_anchor: 60 * 60 * 24 * 7
},
month: {
name: {
singular: 'Month'
, plural: 'Months'
, display: 'm'
}
, to_anchor: 60 * 60 * 24 * daysInYear / 12
}
, year: {
singular: 'Month',
plural: 'Months',
display: 'm'
},
to_anchor: 60 * 60 * 24 * daysInYear / 12
},
year: {
name: {
singular: 'Year'
, plural: 'Years'
, display: 'yr'
}
, to_anchor: 60 * 60 * 24 * daysInYear
singular: 'Year',
plural: 'Years',
display: 'yr'
},
to_anchor: 60 * 60 * 24 * daysInYear
}

@@ -90,9 +90,9 @@ };

module.exports = {
metric: time
, _anchors: {
metric: time,
_anchors: {
metric: {
unit: 's'
, ratio: 1
unit: 's',
ratio: 1
}
}
};

@@ -1,118 +0,118 @@

var metric
, imperial;
var metric, imperial;
metric = {
mm3: {
name: {
singular: 'Cubic Millimeter'
, plural: 'Cubic Millimeters'
, display: 'mm³'
}
, to_anchor: 1/1000000
}
, cm3: {
name: {
singular: 'Cubic Centimeter'
, plural: 'Cubic Centimeters'
, display: 'cm³'
}
, to_anchor: 1/1000
}
, ml: {
singular: 'Cubic Millimeter',
plural: 'Cubic Millimeters',
display: 'mm³'
},
to_anchor: 1 / 1000000
},
cm3: {
name: {
singular: 'Millilitre'
, plural: 'Millilitres'
, display: 'ml'
}
, to_anchor: 1/1000
}
, cl: {
singular: 'Cubic Centimeter',
plural: 'Cubic Centimeters',
display: 'cm³'
},
to_anchor: 1 / 1000
},
ml: {
name: {
singular: 'Centilitre'
, plural: 'Centilitres'
, display: 'cl'
}
, to_anchor: 1/100
}
, dl: {
singular: 'Millilitre',
plural: 'Millilitres',
display: 'ml'
},
to_anchor: 1 / 1000
},
cl: {
name: {
singular: 'Decilitre'
, plural: 'Decilitres'
, display: 'dl'
}
, to_anchor: 1/10
}
, l: {
singular: 'Centilitre',
plural: 'Centilitres',
display: 'cl'
},
to_anchor: 1 / 100
},
dl: {
name: {
singular: 'Litre'
, plural: 'Litres'
, display: 'l'
}
, to_anchor: 1
}
, m3: {
singular: 'Decilitre',
plural: 'Decilitres',
display: 'dl'
},
to_anchor: 1 / 10
},
l: {
name: {
singular: 'Cubic meter'
, plural: 'Cubic meters'
, display: 'm³'
}
, to_anchor: 1000
}
, km3: {
singular: 'Litre',
plural: 'Litres',
display: 'l'
},
to_anchor: 1
},
m3: {
name: {
singular: 'Cubic kilometer'
, plural: 'Cubic kilometers'
, display: 'km³'
}
, to_anchor: 1000000000000
singular: 'Cubic meter',
plural: 'Cubic meters',
display: 'm³'
},
to_anchor: 1000
},
km3: {
name: {
singular: 'Cubic kilometer',
plural: 'Cubic kilometers',
display: 'km³'
},
to_anchor: 1000000000000
}
// Swedish units
, krm: {
// Swedish units
,
krm: {
name: {
singular: 'Matsked'
, plural: 'Matskedar'
, display: 'krm'
}
, to_anchor: 1/1000
}
, tsk: {
singular: 'Matsked',
plural: 'Matskedar',
display: 'krm'
},
to_anchor: 1 / 1000
},
tsk: {
name: {
singular: 'Tesked'
, plural: 'Teskedar'
, display: 'tsk'
}
, to_anchor: 5/1000
}
, msk: {
singular: 'Tesked',
plural: 'Teskedar',
display: 'tsk'
},
to_anchor: 5 / 1000
},
msk: {
name: {
singular: 'Matsked'
, plural: 'Matskedar'
, display: 'msk'
}
, to_anchor: 15/1000
}
, kkp: {
singular: 'Matsked',
plural: 'Matskedar',
display: 'msk'
},
to_anchor: 15 / 1000
},
kkp: {
name: {
singular: 'Kaffekopp'
, plural: 'Kaffekoppar'
, display: 'kkp'
}
, to_anchor: 150/1000
}
, glas: {
singular: 'Kaffekopp',
plural: 'Kaffekoppar',
display: 'kkp'
},
to_anchor: 150 / 1000
},
glas: {
name: {
singular: 'Glas'
, plural: 'Glas'
, display: 'glas'
}
, to_anchor: 200/1000
}
, kanna: {
singular: 'Glas',
plural: 'Glas',
display: 'glas'
},
to_anchor: 200 / 1000
},
kanna: {
name: {
singular: 'Kanna'
, plural: 'Kannor'
, display: 'kanna'
}
, to_anchor: 2.617
singular: 'Kanna',
plural: 'Kannor',
display: 'kanna'
},
to_anchor: 2.617
}

@@ -124,87 +124,87 @@ };

name: {
singular: 'Teaspoon'
, plural: 'Teaspoons'
, display: 'tsp'
}
, to_anchor: 1/6
}
, Tbs: {
singular: 'Teaspoon',
plural: 'Teaspoons',
display: 'tsp'
},
to_anchor: 1 / 6
},
Tbs: {
name: {
singular: 'Tablespoon'
, plural: 'Tablespoons'
, display: 'tbsp'
}
, to_anchor: 1/2
}
, in3: {
singular: 'Tablespoon',
plural: 'Tablespoons',
display: 'tbsp'
},
to_anchor: 1 / 2
},
in3: {
name: {
singular: 'Cubic inch'
, plural: 'Cubic inches'
, display: 'in³'
}
, to_anchor: 0.55411
}
, 'fl-oz': {
singular: 'Cubic inch',
plural: 'Cubic inches',
display: 'in³'
},
to_anchor: 0.55411
},
'fl-oz': {
name: {
singular: 'Fluid Ounce'
, plural: 'Fluid Ounces'
, display: 'fl-oz'
}
, to_anchor: 1
}
, cup: {
singular: 'Fluid Ounce',
plural: 'Fluid Ounces',
display: 'fl-oz'
},
to_anchor: 1
},
cup: {
name: {
singular: 'Cup'
, plural: 'Cups'
, display: 'cup'
}
, to_anchor: 8
}
, pnt: {
singular: 'Cup',
plural: 'Cups',
display: 'cup'
},
to_anchor: 8
},
pnt: {
name: {
singular: 'Pint'
, plural: 'Pints'
, display: 'pint'
}
, to_anchor: 16
}
, qt: {
singular: 'Pint',
plural: 'Pints',
display: 'pint'
},
to_anchor: 16
},
qt: {
name: {
singular: 'Quart'
, plural: 'Quarts'
, display: 'qt'
}
, to_anchor: 32
}
, gal: {
singular: 'Quart',
plural: 'Quarts',
display: 'qt'
},
to_anchor: 32
},
gal: {
name: {
singular: 'Gallon'
, plural: 'Gallons'
, display: 'g'
}
, to_anchor: 128
}
, ft3: {
singular: 'Gallon',
plural: 'Gallons',
display: 'g'
},
to_anchor: 128
},
ft3: {
name: {
singular: 'Cubic foot'
, plural: 'Cubic feet'
, display: 'ft³'
}
, to_anchor: 957.506
}
, yd3: {
singular: 'Cubic foot',
plural: 'Cubic feet',
display: 'ft³'
},
to_anchor: 957.506
},
yd3: {
name: {
singular: 'Cubic yard'
, plural: 'Cubic yards'
, display: 'yd³'
}
, to_anchor: 25852.7
}
, bbl: {
singular: 'Cubic yard',
plural: 'Cubic yards',
display: 'yd³'
},
to_anchor: 25852.7
},
bbl: {
name: {
singular: 'Oil barrel'
, plural: 'Oil barrels'
, display: 'bbl'
}
, to_anchor: 5376
singular: 'Oil barrel',
plural: 'Oil barrels',
display: 'bbl'
},
to_anchor: 5376
}

@@ -214,14 +214,14 @@ };

module.exports = {
metric: metric
, imperial: imperial
, _anchors: {
metric: metric,
imperial: imperial,
_anchors: {
metric: {
unit: 'l'
, ratio: 33.8140226
unit: 'l',
ratio: 33.8140226
},
imperial: {
unit: 'fl-oz',
ratio: 1 / 33.8140226
}
, imperial: {
unit: 'fl-oz'
, ratio: 1/33.8140226
}
}
};

@@ -1,22 +0,22 @@

var convert
, keys = require('lodash.keys')
, each = require('lodash.foreach')
, measures = {
length: require('./definitions/length')
, area: require('./definitions/area')
, mass: require('./definitions/mass')
, volume: require('./definitions/volume')
, each: require('./definitions/each')
, temperature: require('./definitions/temperature')
, time: require('./definitions/time')
, digital: require('./definitions/digital')
, partsPer: require('./definitions/partsPer')
, speed: require('./definitions/speed')
, pressure: require('./definitions/pressure')
, force: require('./definitions/force')
}
, Converter;
var convert, keys = require('lodash.keys'),
each = require('lodash.foreach'),
measures = {
length: require('./definitions/length'),
area: require('./definitions/area'),
mass: require('./definitions/mass'),
volume: require('./definitions/volume'),
each: require('./definitions/each'),
temperature: require('./definitions/temperature'),
time: require('./definitions/time'),
digital: require('./definitions/digital'),
partsPer: require('./definitions/partsPer'),
speed: require('./definitions/speed'),
pressure: require('./definitions/pressure'),
force: require('./definitions/force'),
density: require('./definitions/density')
},
Converter;
Converter = function (numerator, denominator) {
if(denominator)
Converter = function(numerator, denominator) {
if (denominator)
this.val = numerator / denominator;

@@ -28,6 +28,6 @@ else

/**
* Lets the converter know the source unit abbreviation
*/
Converter.prototype.from = function (from) {
if(this.destination)
* Lets the converter know the source unit abbreviation
*/
Converter.prototype.from = function(from) {
if (this.destination)
throw new Error('.from must be called before .to');

@@ -37,3 +37,3 @@

if(!this.origin) {
if (!this.origin) {
this.throwUnsupportedUnitError(from);

@@ -46,6 +46,6 @@ }

/**
* Converts the unit and returns the value
*/
Converter.prototype.to = function (to) {
if(!this.origin)
* Converts the unit and returns the value
*/
Converter.prototype.to = function(to) {
if (!this.origin)
throw new Error('.to must be called after .from');

@@ -55,6 +55,5 @@

var result
, transform;
var result, transform;
if(!this.destination) {
if (!this.destination) {
this.throwUnsupportedUnitError(to);

@@ -69,17 +68,17 @@ }

// You can't go from liquid to mass, for example
if(this.destination.measure != this.origin.measure) {
throw new Error('Cannot convert incompatible measures of '
+ this.destination.measure + ' and ' + this.origin.measure);
if (this.destination.measure != this.origin.measure) {
throw new Error('Cannot convert incompatible measures of ' +
this.destination.measure + ' and ' + this.origin.measure);
}
/**
* Convert from the source value to its anchor inside the system
*/
* Convert from the source value to its anchor inside the system
*/
result = this.val * this.origin.unit.to_anchor;
/**
* For some changes it's a simple shift (C to K)
* So we'll add it when convering into the unit
* and substract it when converting from the unit
*/
* For some changes it's a simple shift (C to K)
* So we'll add it when convering into the unit
* and substract it when converting from the unit
*/
if (this.destination.unit.anchor_shift) {

@@ -95,7 +94,7 @@ result += this.destination.unit.anchor_shift;

/**
* Convert from one system to another through the anchor ratio. Some conversions
* aren't ratio based or require more than a simple shift. We can provide a custom
* transform here to provide the direct result
*/
if(this.origin.system != this.destination.system) {
* Convert from one system to another through the anchor ratio. Some conversions
* aren't ratio based or require more than a simple shift. We can provide a custom
* transform here to provide the direct result
*/
if (this.origin.system != this.destination.system) {
transform = measures[this.origin.measure]._anchors[this.origin.system].transform;

@@ -109,4 +108,4 @@ if (typeof transform === 'function') {

/**
* Convert to another unit inside the destination system
*/
* Convert to another unit inside the destination system
*/
return result / this.destination.unit.to_anchor;

@@ -116,10 +115,12 @@ };

/**
* Converts the unit to the best available unit.
*/
* Converts the unit to the best available unit.
*/
Converter.prototype.toBest = function(options) {
if(!this.origin)
if (!this.origin)
throw new Error('.toBest must be called after .from');
if (options == null) {
options = { exclude: [] };
options = {
exclude: []
};
}

@@ -129,6 +130,6 @@

/**
Looks through every possibility for the 'best' available unit.
i.e. Where the value has the fewest numbers before the decimal point,
but is still higher than 1.
*/
Looks through every possibility for the 'best' available unit.
i.e. Where the value has the fewest numbers before the decimal point,
but is still higher than 1.
*/
each(this.possibilities(), function(possibility) {

@@ -142,7 +143,7 @@ var unit = this.describe(possibility);

best = {
val: result
, unit: possibility
, singular: unit.singular
, plural: unit.plural
, display: unit.display
val: result,
unit: possibility,
singular: unit.singular,
plural: unit.plural,
display: unit.display
};

@@ -157,19 +158,19 @@ }

/**
* Finds the unit
*/
Converter.prototype.getUnit = function (abbr) {
* Finds the unit
*/
Converter.prototype.getUnit = function(abbr) {
var found;
each(measures, function (systems, measure) {
each(systems, function (units, system) {
if(system === '_anchors')
each(measures, function(systems, measure) {
each(systems, function(units, system) {
if (system === '_anchors')
return false;
each(units, function (unit, testAbbr) {
if(testAbbr === abbr) {
each(units, function(unit, testAbbr) {
if (testAbbr === abbr) {
found = {
abbr: abbr
, measure: measure
, system: system
, unit: unit
abbr: abbr,
measure: measure,
system: system,
unit: unit
};

@@ -180,7 +181,7 @@ return false;

if(found)
if (found)
return false;
});
if(found)
if (found)
return false;

@@ -194,8 +195,8 @@ });

return {
abbr: resp.abbr
, measure: resp.measure
, system: resp.system
, singular: resp.unit.name.singular
, plural: resp.unit.name.plural
, display: resp.unit.name.display
abbr: resp.abbr,
measure: resp.measure,
system: resp.system,
singular: resp.unit.name.singular,
plural: resp.unit.name.plural,
display: resp.unit.name.display
};

@@ -205,5 +206,5 @@ };

/**
* An alias for getUnit
*/
Converter.prototype.describe = function (abbr) {
* An alias for getUnit
*/
Converter.prototype.describe = function(abbr) {
var resp = Converter.prototype.getUnit(abbr);

@@ -215,21 +216,21 @@

/**
* Detailed list of all supported units
*/
Converter.prototype.list = function (measure) {
* Detailed list of all supported units
*/
Converter.prototype.list = function(measure) {
var list = [];
each(measures, function (systems, testMeasure) {
if(measure && measure !== testMeasure)
each(measures, function(systems, testMeasure) {
if (measure && measure !== testMeasure)
return;
each(systems, function (units, system) {
if(system == '_anchors')
each(systems, function(units, system) {
if (system == '_anchors')
return false;
each(units, function (unit, abbr) {
each(units, function(unit, abbr) {
list = list.concat(describe({
abbr: abbr,
measure: testMeasure
, system: system
, unit: unit
measure: testMeasure,
system: system,
unit: unit
}));

@@ -243,8 +244,8 @@ });

Converter.prototype.throwUnsupportedUnitError = function (what) {
Converter.prototype.throwUnsupportedUnitError = function(what) {
var validUnits = [];
each(measures, function (systems, measure) {
each(systems, function (units, system) {
if(system == '_anchors')
each(measures, function(systems, measure) {
each(systems, function(units, system) {
if (system == '_anchors')
return false;

@@ -260,24 +261,24 @@

/**
* Returns the abbreviated measures that the value can be
* converted to.
*/
Converter.prototype.possibilities = function (measure) {
* Returns the abbreviated measures that the value can be
* converted to.
*/
Converter.prototype.possibilities = function(measure) {
var possibilities = [];
if(!this.origin && !measure) {
each(keys(measures), function (measure){
each(measures[measure], function (units, system) {
if(system == '_anchors')
return false;
if (!this.origin && !measure) {
each(keys(measures), function(measure) {
each(measures[measure], function(units, system) {
if (system == '_anchors')
return false;
possibilities = possibilities.concat(keys(units));
});
});
possibilities = possibilities.concat(keys(units));
});
});
} else {
measure = measure || this.origin.measure;
each(measures[measure], function (units, system) {
if(system == '_anchors')
return false;
measure = measure || this.origin.measure;
each(measures[measure], function(units, system) {
if (system == '_anchors')
return false;
possibilities = possibilities.concat(keys(units));
});
possibilities = possibilities.concat(keys(units));
});
}

@@ -289,10 +290,10 @@

/**
* Returns the abbreviated measures that the value can be
* converted to.
*/
Converter.prototype.measures = function () {
* Returns the abbreviated measures that the value can be
* converted to.
*/
Converter.prototype.measures = function() {
return keys(measures);
};
convert = function (value) {
convert = function(value) {
return new Converter(value);

@@ -299,0 +300,0 @@ };

@@ -1,3 +0,3 @@

module.exports = function (expected, actual) {
module.exports = function(expected, actual) {
return Math.abs((expected - actual) / actual);
}
};
{
"name": "corva-convert-units",
"version": "1.3.1",
"version": "1.4.0",
"description": "Convert between quantities in different units",

@@ -5,0 +5,0 @@ "main": "lib",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc