haimkastner / unitsnet-js

A better way to hold unit variables and easily convert to the destination unit
https://www.npmjs.com/package/unitsnet-js
MIT License
25 stars 8 forks source link

Missing Unit Abbreviations #23

Closed jules-js closed 1 year ago

jules-js commented 1 year ago

Hello,

I've been using the unitsnet-js library and I noticed that some of the unit abbreviations seem to be missing, particularly for units of length and force. For instance, I could not find abbreviations for kilometers, centimeters, millimeters, and kilonewtons etc.

Here's a simple example demonstrating this:

import { Length, LengthUnits } from 'unitsnet-js';

let length = Length.FromLengths(5, LengthUnits.Kilometers);
console.log(length.getUnitAbbreviation());  // Expected output: 'km'

In this case, I'd expect the output to be 'km' for kilometers, but it seems like the function returns an empty string.

This appears to be a significant issue, as it limits the functionality of the library. Are there any plans to add these missing abbreviations in a future update? If these abbreviations are intentionally missing, could you provide guidance on the best way to handle these cases?

Thank you for your attention to the matter.

maltonic commented 1 year ago

Hello,

i was having exact the same issue but unfortunately no fix ;(

Can someone help on this?

Thank you

haimkastner commented 1 year ago

Hi @jules-js

The "Length" object once created, is not a "Kilometer" or any other unit system, it's just "Length". So, in order to get the abbreviation of a kilometer from the Length object you should use it like this:

First, create the object:

let length = new Length(5, LengthUnits.Kilometers);

Or

let length = Length.FromKilometers(5);

Both ways will create the Length object.

Now, if you want to get the value as Kilometer you need to specify it like this:

console.log(length.Kilometers);

And the same if you want the abbreviation of Kilometer you need to specify it like this:

console.log(length.getUnitAbbreviation(LengthUnits.Kilometers));

And if you want the Kilometer value with the abbreviation as a string specify it like this:

console.log(length.toString(LengthUnits.Kilometers));

Regarding Kilometer abbreviation, I have checked it, and it looks like there is no attribution for it. The reason is, that all the units systems conversion, formulas, and abbreviations all generated from the UnitsNet Definition Files.

And since it's not contained unit abbreviations for prefix units (such as Kilometer, Centimeter, etc.) there is no attribution on the JS library as well.

See here how the definition of Length defined.

If you think that abbreviations for unit prefixes are valuable, please open an issue to the UnitsNet project, and once they will accept it and will add abbreviations support to unit prefixes, please re-open this issue and I will align JS library to use prefixes abbreviations as well.

Thank you!

haimkastner commented 1 year ago

@jules-js This issue was fixed for the Python library thanks to haimkastner/unitsnet-py#13 , and now it's also fixed for the TS package with #24

jules-js commented 1 year ago

@haimkastner Thank you!