Loading repository data…
Loading repository data…
charpeni / repository
🔗A lightweight and trustworthy URL polyfill for React Native.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A lightweight and trustworthy URL polyfill for React Native, based on the WHATWG URL Standard optimized for React Native.
URL and whatwg-url.react-native-url-polyfill/auto will be no-op on web.[!IMPORTANT] As mentioned above, Unicode support has been stripped out to keep this polyfill lightweight on mobile. Therefore, non-ASCII characters aren't supported in the hostname.
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.
[!NOTE] Known issues (non-exhaustive) with React Native's URL are:
- URL cannot handle "localhost" domain for base url react-native#26019.
- URL implementation should add a trailing slash to the base react-native#25717.
- URL incorrectly adds trailing slash react-native#24428.
- Creating an instance of URL like:
new URL('http://facebook.com')throws an exception react-native#16434.
That's why you may need this external dependency. If you use URL within your app, you should look at the installation steps below!
[!NOTE] Adding
react-native-url-polyfillto React Native source code only adds 📦 25.19 kB (+3%) (as of RN 0.86.0) to the JavaScript bundle.
First, you need to install the polyfill, which can be done with Yarn, npm, and others.
yarn add react-native-url-polyfill
Then, the polyfill can be used in multiple ways. Pick your preferred option.
[!TIP] To verify if the polyfill has been correctly applied, you can check if the global variable
REACT_NATIVE_URL_POLYFILLcontains the current package and version like:react-native-url-polyfill@CURRENT_VERSION.
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';
If you want to apply the polyfill when you're ready, you can import setupURLPolyfill and call it yourself.
import { setupURLPolyfill } from 'react-native-url-polyfill';
setupURLPolyfill();
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');
Run the URL workloads on Node with yarn benchmark [samples], or on the
optimized standalone Hermes runtime bundled with React Native with
yarn benchmark:hermes [samples]. The Hermes command currently relies on the
standalone runtime shipped for supported host platforms (macOS in React Native
0.81.4); HERMES_BIN and HERMESC_BIN can point to another matching binary pair.
These desktop standalone-Hermes measurements are not representative of device
performance. Unsupported optional implementations and operations are reported
and skipped.
react-native-url-polyfill is MIT licensed.