Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-native-polyfill-globals
Advanced tools
Polyfills and patches missing or partially supported web and core APIs
Polyfills and patches missing or partially supported web and core APIs.
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.
FormData
is partially implemented
FileReader.readAsArrayBuffer
is not implemented
ReadableStream
is not supported and, by extension, Response.body
is not implemented. Related discussions:
btoa
and atob
are not supportedTextEncoder
and TextDecoder
are not supported$ npm install react-native-polyfill-globals
Install the above as necessary.
Import the polyfill
function and call it whenever.
import { polyfill } from 'react-native-polyfill-globals';
polyfill();
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';
import { polyfill as polyfillBase64 } 'react-native-polyfill-globals/src/base64';
import { polyfill as polyfillEncoding } 'react-native-polyfill-globals/src/encoding';
import { polyfill as polyfillReadableStream } 'react-native-polyfill-globals/src/readable-stream';
import { polyfill as polyfillURL } 'react-native-polyfill-globals/src/url';
import { polyfill as polyfillFetch } 'react-native-polyfill-globals/src/fetch';
Patch files located at the patches directory install additional polyfills.
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
FormData.set
FormData
handles Blob
s correctlyFileReader.readAsArrayBuffer
URL
and URLSearchParams
from react-native-url-polyfillReadableStream
from web-streams-polyfillbtoa
and atob
from base-64TextEncoder
and TextDecoder
from text-encodingfetch
for text streaming from react-native-fetch-apiNote that Metro, React Native's bundler, at this time does not support tree-shaking nor dead code elimination. As such, beware if you are applying polyfills selectively with the JavaScript API and don't call the functions, the code will be included in the production bundle regardless. If you don't need a given polyfill, do not import it at all.
Released under the MIT License.
FAQs
Polyfills and patches missing or partially supported web and core APIs
The npm package react-native-polyfill-globals receives a total of 8,828 weekly downloads. As such, react-native-polyfill-globals popularity was classified as popular.
We found that react-native-polyfill-globals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.