numbro
numbro copied to clipboard
Specify and document a precedence when a postfix can have serveral meanings
While working on https://github.com/BenjaminVanRyseghem/numbro/pull/590, I came across ambiguities in the unformatter.
Initially, I tried to use B
as the abbreviation for "trillion", as that would be "Billion" in German. This, however, made some tests fail, as B
is also a valid postfix in the byte unformatter, representing bytes.
Obviously, numbro cannot solve this problem completely, as strings like "1B" are inherently ambiguous in German. To migitate the problem, however, it would be possible to:
- define an order of execution/precedence on the formatters (which kind of formatted number does the unformatter try to recognize first/second/...?) and add this to the docs (http://numbrojs.com/format.html#unformat)
- make the unformatter take a second argument specifying the type of value in question (number, currency, byte, etc.)
Thanks for the report.
Indeed, the unformatter is quite ambiguous and fails more that I dare to admit :smile:
I would go for the second approach:
- it matches better with how
format
works - it could ultimately solves all the issues
- it's more future-proof
My 2cts :smile:
I don't think the two approaches are mutually exclusive. Having a unformat
function that only takes the input as argument might be useful where the someone has no clue about what kind of numeric thing has been input. We should just make sure the user knows what he can expect from that function.
Anyways, I am sorry I probably won't have time to tackle this (as a matter of fact, I only came here because I need that language file fix two layers up the stream...).