corva-convert-units
Advanced tools
Comparing version 1.10.24 to 1.10.25
@@ -89,4 +89,9 @@ var convert, keys = require('lodash.keys'), | ||
if (this.destination.measure != this.origin.measure) { | ||
throw new Error('Cannot convert incompatible measures of ' + | ||
this.destination.measure + ' and ' + this.origin.measure); | ||
var pair = this.getUnitForPair(this.destination.abbr, this.origin.abbr); | ||
if (!pair) { | ||
throw new Error('Cannot convert incompatible measures of ' + | ||
this.destination.measure + ' and ' + this.origin.measure); | ||
} | ||
this.destination = pair[0]; | ||
this.origin = pair[1]; | ||
} | ||
@@ -206,2 +211,50 @@ | ||
Converter.prototype.getUnitForPair = function(abbrOne, abbrTwo) { | ||
var foundOne; | ||
var foundTwo; | ||
each(measures, function(systems, measure) { | ||
each(systems, function(units, system) { | ||
if (system === '_anchors') | ||
return false; | ||
each(units, function(unit, testAbbr) { | ||
if (testAbbr === abbrOne) { | ||
foundOne = { | ||
abbr: abbrOne, | ||
measure: measure, | ||
system: system, | ||
unit: unit | ||
}; | ||
} else if (testAbbr === abbrTwo) { | ||
foundTwo = { | ||
abbr: abbrTwo, | ||
measure: measure, | ||
system: system, | ||
unit: unit | ||
}; | ||
} | ||
if (foundOne && foundTwo) { | ||
return false; | ||
} | ||
}); | ||
if (foundOne && foundTwo) { | ||
return false; | ||
} | ||
}); | ||
if (foundOne && foundTwo) { | ||
return false; | ||
} else { | ||
foundOne = null; | ||
foundTwo = null; | ||
} | ||
}); | ||
return foundOne && foundTwo ? [foundOne, foundTwo] : null; | ||
}; | ||
var describe = function(resp) { | ||
@@ -208,0 +261,0 @@ return { |
{ | ||
"name": "corva-convert-units", | ||
"version": "1.10.24", | ||
"version": "1.10.25", | ||
"description": "Convert between quantities in different units", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
56263
2900