Would it be possible to implement an unformat option for Intl Locale?

When a user is inputting very large numbers it's nice to allow them to
format the number (or have it auto-formatted) so they can read what they
are typing. It would be great to be able to convert it back to a number /
date / etc. based on their locale.

Something like:
```
Intl.NumberFormat(locale).unformat(string)
```

I currently do it myself for numbers by creating an unformatter function
using the `decimal` object in `formatToParts()`
```
import _ from "lodash"

const locale = window.navigator.userLanguage || window.navigator.language;
const numberFormatter = new Intl.NumberFormat(locale)
const numberDecimalString = _.find(numberFormatter.formatToParts(0.1),
{type: "decimal"}).value
const stripNonNumeric = string => string.replace(/\D/g,'');
const splitStringToFloat = splitString => {
const intString = stripNonNumeric(splitString[0])
const decmalString = stripNonNumeric(splitString[1])
return parseFloat(`${intString}.${decmalString}`)
}
const numberUnformatter = string => {
const splitString = string.split(numberDecimalString)
return splitStringToFloat(splitString)
}
```

It would also be great to be able to do the same for dates and other Intl
formats.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to