Ryan King (2019-06-25T22:41:16.000Z)
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190625/2450a458/attachment.html>
ryan.king1809 at gmail.com (2019-06-25T22:47:19.171Z)
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.
ryan.king1809 at gmail.com (2019-06-25T22:46:48.194Z)
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.
ryan.king1809 at gmail.com (2019-06-25T22:46:06.619Z)
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.
ryan.king1809 at gmail.com (2019-06-25T22:44:59.859Z)
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.