Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getUnits and getAliases addresses #48 #53

Merged
merged 2 commits into from
Oct 14, 2015

Conversation

lukelaws
Copy link
Contributor

@lukelaws lukelaws commented Oct 9, 2015

This is one solution to the issue. In #14 @rage-shadowman had mentioned "Another alternative, if you don't want ambiguous arrays, would be to return only the unit names (ie: for "" return "liter" -- the name sans the "<>" chars) and a getAliases method to get all the aliases for a named unit (["l", "L", "liter", "liters", "litre", "litres"]) or maybe event all the alternative aliases for a given alias (such that getAlternatives("liter") returns an identical array to getAlternatives("L"))."

I agree the grouped arrays are ambiguous, so I'm using that approach:

Qty.getUnits('currency'); // => [ 'dollar', 'cents' ]
Qty.getAliases('m'); // => [ 'm', 'meter', 'meters', 'metre', 'metres' ]

So only one name for each unit is returned.
Also:

Qty.getUnits(); // => [ 'acre','Ah','ampere','AMU','angstrom', ...]

So getUnits is sorted to make it perfect for feeding choices to the user. (Select box, predictive input)

@gentooboontoo also mentioned the getAliases method and again i agree, these should be separate functions. If this goes over well I can make a separate commit for the getPrefixes but I think there are quite a few versions of that that looked great already. They just are bundled up with these other changes.

Thanks for js-quantities! It's working out for us.

@gentooboontoo
Copy link
Owner

Great, thank you for the PR. I think it is the right API.

As a side note, I would have preferred to keep the units identifiers hidden and encapsulated but since I have not found a way to avoid it, this PR is the good opportunity to include this feature.

gentooboontoo added a commit that referenced this pull request Oct 14, 2015
Add getUnits and getAliases 

Addresses #48
@gentooboontoo gentooboontoo merged commit ba60d89 into gentooboontoo:master Oct 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants