gentooboontoo / js-quantities

JavaScript library for quantity calculation and unit conversion
http://gentooboontoo.github.io/js-quantities/
MIT License
396 stars 102 forks source link

Some units listed with Qty.getUnits are unrecognized #101

Closed harmanpa closed 4 years ago

harmanpa commented 4 years ago

Qty.getUnits('volume') lists a set of units including 'beerbarrel' and 'oilbarrel'.

However Qty('beerbarrel') results in an unrecognized unit error.

The reason for this appears to be that in definitions.js, the unit is defined as: "<beerbarrel>": [["bl","bl-us","beer-barrel","beer-barrels"], 0.1173477658, "volume", ["<meter>","<meter>","<meter>"]], where 'beerbarrel' is not in the list of aliases.

nwesterman commented 4 years ago

Would like to second this. Was attempting to get a list of all known aliases, but it throws an error when iterating over the provided list. Reproducible with runkit https://npm.runkit.com/js-quantities

var Qty = require("js-quantities")
const allUnits = Qty.getUnits()
const allias = allUnits.map(u => Qty.getAliases(u))

Error:

QtyErrorProperties 
message: "Unit not recognized"
name: "QtyError"

Running with a try/catch

var Qty = require("js-quantities")
const allUnits = Qty.getUnits()
const alliases = []
for(const unit of allUnits)
{
    try {
        Qty.getAliases(unit)
    }
    catch(e) {
        alliases.push(unit)
    }
}
console.log(alliases)

yields these 3 units as not being understood ["beerbarrel", "beerbarrel-imp", "oilbarrel"]

bcowgill commented 3 years ago

Was just evaluating version 1.7.5 and still seeing this problem.

volume: beerbarrel: Qty(1, beerbarrel) QtyError: Unit not recognized; getAliases(beerbarrel) QtyError: Unit not recognized beerbarrel-imp: Qty(1, beerbarrel-imp) QtyError: Unit not recognized; getAliases(beerbarrel-imp) QtyError: Unit not recognized oilbarrel: Qty(1, oilbarrel) QtyError: Unit not recognized; getAliases(oilbarrel) QtyError: Unit not recognized

apologies if this is queued for release or something.