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

Access to unit list #48

Closed phrozen closed 8 years ago

phrozen commented 9 years ago

Hi, I'm using this awesome library for a project and although there exist a way to get the "well-known kinds" it is useless to me without having a way to obtain the unit list in that category (to put in a select widget or something), the code already has the list, it is just a matter of exposing it and maybe filtering it.

Thoughts?

gentooboontoo commented 9 years ago

Could something like what was proposed in PR #14 fit your need?

getUnits("radiation") -> [["Gy","gray","grays"],["R","roentgen"], ...]

Each unit would be grouped by alias.

Side questions, would you display every alias or arbitrarily one of them? How will you filter out unneeded units like light years or astronomical units from length kind for instance?

phrozen commented 9 years ago

That would be great!! Is that commit on master?

I guess one way to select them is either take the SI canonical form or the full name (either m or meter, N or Netwon) I would have to check once I have the list via getUnits() and maybe select (Hopefully) alias[0].

I might not need to filter out some units, but in case I would, I would use a dictionary build after having access to the units by kind, and filter them like that. Thanks!

lukelaws commented 9 years ago

Hi there, I have a need for this as well. And using it in a select box is also my intention. I read over PR #14 and I agree getting the available units of a particular kind is a separate concern from getting aliases. Would it be acceptable to use the key names in UNITS as a single name for each? This is working well for my application: 398ad8f37633fd2834373a0ab4a4e86b58289dc8

gentooboontoo commented 8 years ago

Fixed by #53