• Stars
    star
    341
  • Rank 123,998 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created about 5 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”—A lightweight and trustworthy URL polyfill for React Native.

Library's logo

React Native URL Polyfill

A lightweight and trustworthy URL polyfill for React Native

Current npm package version. Monthly downloads Current CircleCI build status. PRs welcome! React Native URL Polyfill is released under the MIT license.


react-native-url-polyfill is an implementation of the WHATWG URL Standard optimized for React Native.

  • Lightweight. Uses a forked version of whatwg-url (whatwg-url-without-unicode) where unicode support has been stripped out β€” Going down from 372 KB to 40.9 KB.
  • Trustworthy. Follows closely the URL Standard spec, and relys on unit tests and Detox e2e tests within React Native.
  • Blob support. Supports React Native's Blob without additional steps.
  • Hermes support. Supports Hermes, a JavaScript engine optimized for running React Native.
  • Expo support. Supports Expo and tested against.
  • Web support. Most of the time, this polyfill isn't useful on web and therefore using react-native-url-polyfill/auto will be no-op on web.

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:

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!

Unfortunately, adding react-native-url-polyfill to React Native source code would mean adding πŸ“¦ 73.67 KB (as of RN 0.72) to the JavaScript bundle, that's why it's not included by default.

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 / ponyfill)

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.

More Repositories

1

svelte-example

πŸš€ πŸ“š Some examples to test the Svelte Framework
HTML
87
star
2

ios-simulator-app-exporter

πŸ“² List your iOS simulator devices and their applications, and help you to quickly export them.
JavaScript
71
star
3

react-native-speech-bubble

πŸ’¬ A speech bubble dialog component for React Native.
JavaScript
50
star
4

sync-external-contributions

πŸ“ Sync your external contributions to GitHub :octocat:
JavaScript
36
star
5

react-native-is-catalyst

Tells if the react native app is running on Catalyst
Ruby
16
star
6

react-native-bundle-scale

A command-line interface to see how adding packages affects your React Native JavaScript bundle.
JavaScript
8
star
7

react-native-lib-example-app

πŸš‡ Demonstrate how to create an example app for your RN library using Metro bundler
Objective-C
8
star
8

apollo-cache-persist-compressed

πŸ—œοΈ Compressed cache persistence for Apollo Client
TypeScript
4
star
9

react-native-android-visibility-issue

Java
3
star
10

react-native-backface-visibility

πŸ“š This repository was used to test compatibility of the backfaceVisibility property on iOS and Android
Objective-C
3
star
11

advent-of-code-2018

πŸ“š πŸŽ„ My solutions to the Advent of Code 2018 in ReasonML.
C++
2
star
12

one-of

🎲 Type-safe utilities to return a random element from an array or random entry from an object
TypeScript
2
star
13

circleci-workflow-terminator

A bot to cancel redundant builds from CircleCI workflows.
JavaScript
2
star
14

react-native-circleci

Objective-C
1
star
15

charpeni

1
star
16

charpeni.com

πŸ“ My personal website and blog.
MDX
1
star
17

merge-drivers-cli

A command-line interface to conveniently manage custom git merge drivers.
JavaScript
1
star
18

git-bisect-workshop

JavaScript
1
star
19

react-native-issue-font-weight-custom-fonts

https://github.com/facebook/react-native/issues/25481
Objective-C
1
star