New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@anansi/polyfill

Package Overview
Dependencies
Maintainers
2
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anansi/polyfill

Feature detection triggered dynamic polyfills

  • 1.0.125
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-95.43%
Maintainers
2
Weekly downloads
 
Created
Source

@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 />);
}

Keywords

FAQs

Package last updated on 23 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc