npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-polyfill-globals

v3.1.0

Published

Polyfills and patches missing or partially supported web and core APIs

Downloads

35,192

Readme

react-native-polyfill-globals

npm version ci codecov

Polyfills and patches missing or partially supported web and core APIs.

Motivation

There are several APIs which React Native does not support. When available, they usally are not spec-conformant. This package aims to fill that gap by providing polyfills and patches to said APIs.

As of React Native v0.63.3:

  • URL and URLSearchParams are partially implemented.
    • https://github.com/facebook/react-native/blob/v0.63.3/Libraries/Blob/URL.js#L56
    • https://github.com/facebook/react-native/blob/v0.63.3/Libraries/Blob/URL.js#L115
    • Related discussions:
      • https://github.com/facebook/react-native/pull/30188
      • https://github.com/facebook/react-native/pull/25719
      • https://github.com/facebook/react-native/issues/23922
      • https://github.com/facebook/react-native/issues/24428
      • https://github.com/facebook/react-native/issues/16434
      • https://github.com/facebook/react-native/issues/25717
      • https://github.com/facebook/react-native/issues/26019
  • FormData is partially implemented
    • https://github.com/facebook/react-native/blob/v0.63.3/Libraries/Network/FormData.js
  • FileReader.readAsArrayBuffer is not implemented
    • https://github.com/facebook/react-native/blob/v0.63.3/Libraries/Blob/FileReader.js#L84
    • Related discussions:
      • https://github.com/facebook/react-native/issues/21209
  • ReadableStream is not supported and, by extension, Response.body is not implemented. Related discussions:
    • https://github.com/facebook/react-native/issues/27741
    • https://github.com/facebook/react-native/issues/12912
    • https://github.com/github/fetch/issues/198
    • https://github.com/github/fetch/issues/746
  • btoa and atob are not supported
  • TextEncoder and TextDecoder are not supported
  • ...and others

Installation

$ npm install react-native-polyfill-globals

Peer dependencies

Install the above as necessary.

Included support

Usage

Polyfill all on demand

Import the polyfill function and call it whenever.

import { polyfill } from 'react-native-polyfill-globals';

polyfill();

Polyfill all automatically

Add the following import to the top of your app's entry file, index.js, located at the root of your project.

import 'react-native-polyfill-globals/auto';

Polyfill selectively

import { polyfill as polyfillBase64 } from 'react-native-polyfill-globals/src/base64';
import { polyfill as polyfillEncoding } from 'react-native-polyfill-globals/src/encoding';
import { polyfill as polyfillReadableStream } from 'react-native-polyfill-globals/src/readable-stream';
import { polyfill as polyfillURL } from 'react-native-polyfill-globals/src/url';
import { polyfill as polyfillFetch } from 'react-native-polyfill-globals/src/fetch';
import { polyfill as polyfillCrypto } from 'react-native-polyfill-globals/src/crypto';

Apply patches

Patch files located at the patches directory provide additional polyfills and fixes.

Apply all at once with patch-package:

$ npm install -D patch-package
$ npx patch-package --patch-dir node_modules/react-native-polyfill-globals/patches

Apply invidually with Git:

$ git apply --ignore-whitespace node_modules/react-native-polyfill-globals/react-native+0.63.3.patch

Apply invidually with patch:

$ patch -p1 -i node_modules/react-native-polyfill-globals/react-native+0.63.3.patch

⚠️ Bundling

Note that Metro, React Native's bundler, at this time does not support tree-shaking nor dead code elimination. As such, beware that even if you apply polyfills selectively and don't use them at runtime, the code will be included in the production bundle regardless. If you don't need a given polyfill, do not import it at all.

Related

  • node-libs-react-native - Node.js core modules for React Native.
  • rn-nodeify - Hack to allow React Native projects to use Node core modules and npm modules that use them.
  • ReactNativify - A saner approach on how to use Node.js libraries in React Native.

License

MIT © André Costa Lima