Skip to main content

Intl.ListFormat

A spec-compliant polyfill for Intl.ListFormat fully tested by the official ECMAScript Conformance test suite

npm Version size

Installation#

npm i @formatjs/intl-listformat

Requirements#

Usage#

Via polyfill.io#

You can use polyfill.io URL Builder to create a polyfill script tag for Intl.ListFormat. By default the created URL does not come with any locale data. In order to add locale data, append Intl.ListFormat.~locale.<locale> to your list of features. For example:

<!-- Polyfill Intl.ListFormat, its dependencies & `en` locale data --><script src="https://polyfill.io/v3/polyfill.min.js?features=Intl.ListFormat,Intl.ListFormat.~locale.en"></script>

Simple#

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

Dynamic import + capability detection#

import {shouldPolyfill} from '@formatjs/intl-listformat/should-polyfill'async function polyfill(locale: string) {  // This platform already supports Intl.ListFormat  if (!shouldPolyfill(locale)) {    return  }  // Load the polyfill 1st BEFORE loading data  await import('@formatjs/intl-listformat/polyfill')
  switch (locale) {    default:      await import('@formatjs/intl-listformat/locale-data/en')      break
    case 'fr':      await import('@formatjs/intl-listformat/locale-data/fr')      break  }}

Tests#

This library is fully test262-compliant.