Search code examples
javascriptnumber-formatting

Intl.NumberFormat.prototype.formatToParts support for Safari older version from 13


i got an error on my application that **formaTtoParts** is not defined

TypeError: Intl.NumberFormat(t,{minimumFractionDigits:2}).formatToParts is not a
function. (In 'Intl.NumberFormat(t,{minimumFractionDigits:2}).formatToParts(ri(e))',
 'Intl.NumberFormat(t,{minimumFractionDigits:2}).formatToParts' is undefined)
browser.name:
Mobile Safari UI/WKWebView

device:
iPhone

interface_type:
exception

os:
iOS 12.5.5

Is it possible to find a polyfill please for alternate solution that supports previous version of Safar from 13 ???


Solution

  • https://formatjs.io/docs/react-intl/components#formattednumberparts

    React Intl has a set of React components that provide a declarative way to
     setup an i18n context and format dates, numbers, and strings for display in 
    a web UI. The components render React elements by building on React Intl's imperative API.
    

    this might help us on the device when Intl.NumberFormat.prototype.formatToPartsis not supported

    Here is the file to check more details on the implementation: FormatNumericToParts.ts

    Moreover, can use the @formatjs as a polyfill too

    import '@formatjs/intl-numberformat/polyfill'
    import '@formatjs/intl-numberformat/locale-data/en' // locale-data for en