@anansi/polyfill
Feature detection triggered dynamic polyfills
Last updated a month ago by ntucker .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @anansi/polyfill 
SYNC missed versions from official npm registry.

@anansi/polyfill

This ensures support for Intl localization object, requestIdleCallback and fetch. It does so using feature detection and dynamic imports, allowing browsers that support the features to immediately progress.

Usage

With React:

import ReactDOM from 'react-dom';
import loadPolyfills from '@anansi/polyfill';

import MyApp from './App';

async function init() {
  await loadPolyfills();
  ReactDOM.createRoot(document.body).render(<MyApp />);
}
init();

It's important to delay initilization of your app until these polyfills are loaded. This is provided by the promise returned by loadPolyfills(). Once that promise resolves all polyfills will be loaded into the global object.

Arguments

include: [intl, ric, fetch] | 'all' = 'all'

By default all three polyfills are loaded, but if you don't use a feature (like fetch) you may want to avoid loading it. Do this by passing an array of features you want to include from [intl, ric, fetch].

loadPolyfills(['intl', 'ric']); // fetch won't be loaded

Supporting locales

To support locales other than english, you'll need to import them as well. They weren't included to help with build times for sites that don't need it.

Support spanish and german:

for (const locale of ['es', 'de']) {
  import(
    /* webpackChunkName: "locale-request" */ `intl/locale-data/jsonp/${locale}.js`
  );
}

Detect locale of browser:

import localeFinder from 'browser-locale';

async function init() {
  await loadPolyfills();
  if (
    !global.Intl ||
    typeof global.Intl.DateTimeFormat.prototype.formatToParts !== 'function'
  ) {
    const locale = localeFinder();
    await import(
      /* webpackChunkName: "locale-request" */ `intl/locale-data/jsonp/${locale}.js`
    );
  }
  ReactDOM.createRoot(document.body).render(<MyApp />);
}

Current Tags

  • 1.0.19                                ...           latest (a month ago)

63 Versions

  • 1.0.19                                ...           a month ago
  • 1.0.18                                ...           2 months ago
  • 1.0.17                                ...           2 months ago
  • 1.0.16                                ...           3 months ago
  • 1.0.15                                ...           3 months ago
  • 1.0.14                                ...           3 months ago
  • 1.0.12                                ...           5 months ago
  • 1.0.11                                ...           5 months ago
  • 1.0.10                                ...           6 months ago
  • 1.0.9                                ...           6 months ago
  • 1.0.8                                ...           7 months ago
  • 1.0.7                                ...           8 months ago
  • 1.0.6                                ...           8 months ago
  • 1.0.5                                ...           9 months ago
  • 1.0.4                                ...           9 months ago
  • 1.0.3                                ...           10 months ago
  • 1.0.2                                ...           10 months ago
  • 1.0.1                                ...           10 months ago
  • 1.0.0                                ...           a year ago
  • 0.4.5                                ...           a year ago
  • 0.4.4                                ...           a year ago
  • 0.4.3                                ...           a year ago
  • 0.4.2                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.37                                ...           a year ago
  • 0.3.36                                ...           a year ago
  • 0.3.35                                ...           a year ago
  • 0.3.32                                ...           a year ago
  • 0.3.31                                ...           a year ago
  • 0.3.29                                ...           a year ago
  • 0.3.28                                ...           a year ago
  • 0.3.27                                ...           a year ago
  • 0.3.26                                ...           a year ago
  • 0.3.24                                ...           a year ago
  • 0.3.23                                ...           a year ago
  • 0.3.22                                ...           2 years ago
  • 0.3.21                                ...           2 years ago
  • 0.3.20                                ...           2 years ago
  • 0.3.19                                ...           2 years ago
  • 0.3.18                                ...           2 years ago
  • 0.3.17                                ...           2 years ago
  • 0.3.16                                ...           2 years ago
  • 0.3.15                                ...           2 years ago
  • 0.3.14                                ...           2 years ago
  • 0.3.13                                ...           2 years ago
  • 0.3.13-alpha.0                                ...           2 years ago
  • 0.3.12                                ...           2 years ago
  • 0.3.11                                ...           2 years ago
  • 0.3.10                                ...           2 years ago
  • 0.3.9                                ...           2 years ago
  • 0.3.7                                ...           2 years ago
  • 0.3.6                                ...           2 years ago
  • 0.3.5                                ...           2 years ago
  • 0.3.4                                ...           2 years ago
  • 0.3.3                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 63
This Month 63
Last Day 63
Last Week 0
Last Month 155
Dependencies (5)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |