2.0.0 ā€¢ Published 10 months ago

react-native-url-polyfill v2.0.0

Weekly downloads
41,860
License
MIT
Repository
github
Last release
10 months ago

react-native-url-polyfill is a full implementation of the WHATWG URL Standard that has been optimized for React Native.

  • Trustworthy. Follows closely the URL Standard spec, and relys on unit tests and Detox e2e tests within React Native.
  • Light. Instead of using directly whatwg-url, this polyfill uses a forked version (whatwg-url-without-unicode) where unicode support has been stripped out ā€” Going down from 361 KB to 54 KB.
  • Blob support. Supports React Native's Blob without additional steps.

Why do we need this?

React Native does include a polyfill for URL, but this polyfill is homemade ā€” in order to keep it light-weight ā€” and was initially created to handle specific use cases.

Meanwhile, React Native has grown around that polyfill, then some unexpected errors have arisen.

Known issues (non-exhaustive) with React Native's URL are:

Unfortunately, adding react-native-url-polyfill to React Native source code will means adding šŸ“¦ 84.76 KB to the JavaScript bundle, even if you don't use URL because šŸš‡ Metro doesn't support optional imports.

That's why you may need this external dependency. So, if you use URL within your app, you probably want to take a look at the installation steps below!

Installation

First, you need to install the polyfill, which can be done with Yarn or npm.

Yarn

yarn add react-native-url-polyfill

npm

npm install --save react-native-url-polyfill

Then, the polyfill can be used in multiple ways. Pick your preferred option.

ā„¹ļø To verify if the polyfill has been correctly applied, you can check if the global variable REACT_NATIVE_URL_POLYFILL contains the current package and version like: react-native-url-polyfill@CURRENT_VERSION.

Option 1 (Simple)

Locate your JavaScript entry-point file, commonly called index.js at the root of your React Native project.

Then, import react-native-url-polyfill/auto at the top of your entry-point file, the polyfill will be automatically applied.

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

Option 2 (Flexible)

If you want to apply the polyfill when you're ready, you can import setupURLPolyfill and call it yourself.

āš ļø Metro doesn't support optional imports.

If you do not apply the polyfill, it will still be added to your JavaScript bundle. Even if it's wrapped in a condition, Metro won't strip it in production.

import { setupURLPolyfill } from 'react-native-url-polyfill';

setupURLPolyfill();

Option 3 (Convenient)

If you prefer not to apply this polyfill over React Native's default URL, you can still import those classes manually when you want them.

import { URL, URLSearchParams } from 'react-native-url-polyfill';

const url = new URL('https://github.com');
const searchParams = new URLSearchParams('q=GitHub');

License

react-native-url-polyfill is MIT licensed.

@biconomy-sdk-dev/web3-auth-native@clerk/clerk-expoinfoset-react-nativehilyticsjitsi-meet-rnreact-native-jitsi-meet-lib@rn-toolkit/navigation@infinitebrahmanuniverse/nolb-react-native-umotionfans@everything-registry/sub-chunk-2597ally-sdkorbis-sdknoibu-react-nativemobilenftminteroneid-react-nativeopenlogin-expo-sdkmsw-rn-wrapperpubnubpassportsdkpassportexpobetjok@candypay/elements-mobile-sdk@araviel/web3.js@classon/react-native@criipto/verify-expo@collaboware/solid-authn-react-native@coinbase/mobile-wallet-protocol-host@cristianachavez/orbis-sdk@crqlar/expo-sdk@daily-co/react-native-daily-js@fruits-chain/react-native-upload@functionland/component-library@viewstools/morph@apollosproject/ui-authentication@biconomy-devx/web3-auth-native@biconomy/web3-auth-native@billyjacoby/clerk-react-nativearchitect-react-native-sdk@blackbox-vision/react-native-mercadopago-tokenize-checkout@bouncecode/mrlogin-sdk-rn@basis-theory/basis-theory-react-native@aws-amplify/react-native@getoptimal/react-native@wepin/react-native-sdk@web3auth/react-native-sdk@vcrx/react-native@admin-layout/mobile-navigation-router@aloai/alo-chat-react-native@richardhofmaenner/template-expo-supabase@renkiari/e8-react-native-sdk@triframe/arbiter-react@thirdweb-dev/react-native-compatvolo-sdk-react-native@tosspayments/payment-sdk-react-native@tosspayments/widget-sdk-react-native@tbd54566975/web5-react-native-polyfills@gnonative/react-native@goplayerzero/sdk-react-nativecloudinary-react-native@ground-x/embedded-wallet-rn-sdkclearweatherapiclearweatherapi-vanillalean-react-nativelivekit-react-nativejitsi-meet-stepupnext-auth-with-exporeact-native-goaffproreact-native-pluggy-connectreact-native-raiplayerreact-native-quick-aws4react-native-sdk-fmtechreact-native-sdk-stepupreact-native-sparkle-ai-chatreact-native-ytplreact-native-ytsrrn-reddit-editorrn-sestek-webchatreact-native-jitsi-meet-sdk-fmtechreact-native-method-elementsreact-native-cometchat-calling-componentreact-native-cookie-parserreact-native-chat-streamquaeratabscannersdksalmonwalletv2solid-authn-react-nativesolanasolana-test-package@dtelecom/react-native@exodus/aws-amplify_corestream-chat-react-native-core@dytesdk/mobile@dytesdk/react-native-core@dytesdk/react-native-ui-kit@egiftcard/react-native-compat@epdomains/jetstream-sdksupertokens-react-nativereact-native-phrase-sdktweetnacl-expo-pollyfill@theoplayer/react-native-ui
2.0.0

10 months ago

1.3.0

3 years ago

1.2.0

4 years ago

1.2.0-rc.1

4 years ago

1.2.0-rc.0

4 years ago

1.1.2

4 years ago

1.1.2-rc.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago