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

Possibility to add a method qty.getUnit() ? #109

Open lpatiny opened 3 years ago

lpatiny commented 3 years ago

In order to 'normalize' the user entered quantities in a database I create a JSON that contains 2 properties:

I would like to have a code like:

 const qty = Qty.parse('100 cm^2');
  return {
    SI: qty.baseScalar,
    unit: qty.getUnit(), // this would contain 'cm^2'
  };

I could not find a way to achieve this getUnit with js-quantities. Is this possible ?

adrfantini commented 7 months ago

Isn't Qty(123, 'cm2').units() enough?

Otherwise you can play around with toBase() maybe?