gentooboontoo / js-quantities

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

Swift Converter error: Incompatible units #135

Open demilsson opened 1 year ago

demilsson commented 1 year ago

I'm trying to set up a converter between the inverse units m/s and min/km (meters per second -> minutes per kilometer).

Using simple syntax, this works as expected and provides the correct result:

let qty = new Qty('1.9054 m/s');
let result = qty.to('min/km'); 

// result = 8.7470697316399

However, the same conversion using swiftConverter throws an error instead:

let qty = Qty.swiftConverter('m/s', 'min/km');
let result = qty(1.9054); 

// Throws QtyError: Incompatible units: m/s and min/km

Why can't the swiftConverter do the same conversion? It works for other, non-inverse conversions, so I guess the problem lies somewhere in there.

I use swiftConverter since my application converts hundreds of arrays with thousands of values. Is there a way to work around this?