You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Intl API is a fundamental API to format some values to a local aware string. Unfortunatly, it is missing an API to do the opposite operation : parsing strings to get a value. Currently, only Intl.segmenter is available to properly split out a string based on its locale format. It would be a huge enhancement to have some locale aware parser, for, at least, numbers and date.
Parsing locale aware strings is complicated and would benefits from a native support.
Date & Time
Currently, Date.parse and the future Temporal.*.from are not locale aware (and very likely will never be)
It would be a bliss to have somethind along this line:
constfrenchDateParser=newIntl.DateTimeParser('fr')// very likely with some options when ambiguity needs to be handled.constdateA=frenchDateParser.parse('12/01/2024')// Provide a Date or Temporal object for December 1st, 2024 (not January 12th, 2024)constdateB=frenchDateParser.parse('Lundi 8 Janvier 2024')// Provide a Date or Temporal object for January 8th, 2024consttimeA=frenchDateParser.parse('Le 8 janvier 2024 à 17h')// Provide a Date or Temporal object for January 8th, 2024 at 5pmconsttimeB=frenchDateParser.parse('18h34')// Provide a Date or Temporal object for the time 6:34pm
Currently JS doesn't have a native way to parse a locale formated number such as "10 345,56" (10345.56 in fr-fr locale) or "12,340" (12340 in en-us or 12.34 in fr-fr. Currencies are also tricky as some locales use the symbol as prefix ("$24.35") and others as suffix ("24,35 €")
Having a parser like that would be quite usefull:
constusCurrencyParser=newIntl.NumberParser('en-us',{style: "currency",currency: 'USD'})// options should be very similar to the one used by NumberFormatconstnumA=usCurrencyParser.parse('$24.40')// 24.4constnumB=usCurrencyParser.parse('34,67 €')// NaN ?
The Intl API is a fundamental API to format some values to a local aware string. Unfortunatly, it is missing an API to do the opposite operation : parsing strings to get a value. Currently, only
Intl.segmenter
is available to properly split out a string based on its locale format. It would be a huge enhancement to have some locale aware parser, for, at least, numbers and date.Parsing locale aware strings is complicated and would benefits from a native support.
Date & Time
Currently,
Date.parse
and the futureTemporal.*.from
are not locale aware (and very likely will never be)It would be a bliss to have somethind along this line:
Some libraries offer some solutions:
Numbers
Currently JS doesn't have a native way to parse a locale formated number such as
"10 345,56"
(10345.56
in fr-fr locale) or"12,340"
(12340
in en-us or12.34
in fr-fr. Currencies are also tricky as some locales use the symbol as prefix ("$24.35"
) and others as suffix ("24,35 €"
)Having a parser like that would be quite usefull:
Some libraries offer some solutions:
The text was updated successfully, but these errors were encountered: