Looks like everyone is on top of it. Thanks Steven! On Tue, 25 Jun 2019 at 18:20, Steven R. Loomis <[email protected]> wrote:
> Hi Ryan, > There’s some discussion of parsing at > https://github.com/tc39/ecma402/issues/342 ( for Dates ) and > https://github.com/tc39/ecma402/issues/1 ( for Numbers - yes, issue #1 ). > > One clear direction from the beginning (and painful experience) is to > have formatting and parsing separate. Also, see the arguments against some > uses of parsing that are better off as a date-picker. > > Regards, > > -- > Steven R. Loomis | @srl295 | git.io/srl295 > > > > > El jun. 25, 2019, a las 3:41 p. m., Ryan King <[email protected]> > escribió: > > > > 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 > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

