Skip to content

Commit ac959c7

Browse files
authored
Implement new README layout (#478)
1 parent ae29856 commit ac959c7

File tree

1 file changed

+22
-53
lines changed

1 file changed

+22
-53
lines changed

README.md

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,54 @@
1-
<p align="center">
2-
<img height="60" src="https://user-images.githubusercontent.com/7189823/69501658-06047600-0ed5-11ea-8f54-952bf1afd68c.png" alt="Library's logo">
3-
</p>
4-
5-
<h3 align="center">
6-
React Native URL Polyfill
7-
</h3>
8-
9-
<p align="center">
10-
A lightweight and trustworthy URL polyfill for React Native
11-
</p>
12-
13-
<p align="center">
14-
<a href="https://www.npmjs.org/package/react-native-url-polyfill">
15-
<img src="https://badge.fury.io/js/react-native-url-polyfill.svg" alt="Current npm package version." />
16-
</a>
17-
<a href="https://www.npmjs.org/package/react-native-url-polyfill">
18-
<img src="https://img.shields.io/npm/dm/react-native-url-polyfill" alt="Monthly downloads" />
19-
</a>
20-
<a href="https://circleci.com/gh/charpeni/react-native-url-polyfill">
21-
<img src="https://circleci.com/gh/charpeni/react-native-url-polyfill.svg?style=shield" alt="Current CircleCI build status." />
22-
</a>
23-
<a href="https://circleci.com/gh/charpeni/react-native-url-polyfill">
24-
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs welcome!" />
25-
</a>
26-
<a href="https://github.com/charpeni/react-native-url-polyfill/blob/master/LICENSE">
27-
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="React Native URL Polyfill is released under the MIT license." />
28-
</a>
29-
</p>
30-
31-
<hr />
32-
33-
react-native-url-polyfill is an implementation of the WHATWG [URL Standard](https://url.spec.whatwg.org/) optimized for React Native.
34-
35-
- **Lightweight**. Uses a forked version of [`whatwg-url`](https://github.com/jsdom/whatwg-url) ([`whatwg-url-without-unicode`](https://github.com/charpeni/whatwg-url)) where unicode support has been stripped out — Going down from [372 KB](https://bundlephobia.com/[email protected]) to [40.9 KB](https://bundlephobia.com/[email protected]).
36-
- **Trustworthy**. Follows closely the URL Standard spec, and relys on unit tests and Detox e2e tests within [React Native](https://github.com/facebook/react-native).
1+
# React Native URL Polyfill
2+
3+
<img height="125" src="https://user-images.githubusercontent.com/7189823/69501658-06047600-0ed5-11ea-8f54-952bf1afd68c.png" alt="Library's logo" align="right">
4+
5+
[![Version](https://badge.fury.io/js/react-native-url-polyfill.svg)](https://www.npmjs.org/package/react-native-url-polyfill)
6+
[![Monthly Downloads](https://img.shields.io/npm/dm/react-native-url-polyfill)](https://www.npmjs.org/package/react-native-url-polyfill)
7+
[![CircleCI Status](https://circleci.com/gh/charpeni/react-native-url-polyfill.svg?style=shield)](https://circleci.com/gh/charpeni/react-native-url-polyfill)
8+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/charpeni/react-native-url-polyfill/blob/main/LICENSE)
9+
10+
A lightweight and trustworthy URL polyfill for React Native, based on the WHATWG [URL Standard](https://url.spec.whatwg.org/) optimized for React Native.
11+
12+
- **Lightweight**. Uses a forked version of [`whatwg-url`](https://github.com/jsdom/whatwg-url) ([`whatwg-url-without-unicode`](https://github.com/charpeni/whatwg-url)) where Unicode support has been stripped out—Going down from [372 KB](https://bundlephobia.com/[email protected]) to [40.9 KB](https://bundlephobia.com/[email protected]).
13+
- **Trustworthy**. Follows the URL Standard spec, and relies on unit tests and Detox e2e tests within [React Native](https://github.com/facebook/react-native).
3714
- **Blob support**. Supports React Native's Blob without additional steps.
3815
- **Hermes support**. Supports [Hermes](https://github.com/facebook/hermes), a JavaScript engine optimized for running React Native.
3916
- **Expo support**. Supports [Expo](https://expo.dev/) and tested against.
4017
- **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.
4118

19+
> [!IMPORTANT]
20+
> As mentioned above, Unicode support has been stripped out to keep this polyfill lightweight on mobile. Therefore, [non-ASCII characters](https://unicode.org/reports/tr46/) aren't supported in the hostname.
21+
4222
## Why do we need this?
4323

44-
React Native does include [a polyfill for `URL`](https://github.com/facebook/react-native/blob/8c0c860e38f57e18296f689e47dfb4a54088c260/Libraries/Blob/URL.js#L115-L222), but this polyfill is homemadein order to keep it light-weightand was initially created to handle specific use cases.
24+
React Native does include [a polyfill for `URL`](https://github.com/facebook/react-native/blob/8c0c860e38f57e18296f689e47dfb4a54088c260/Libraries/Blob/URL.js#L115-L222), but this polyfill is homemadein order to keep it light-weightand was initially created to handle specific use cases.
4525

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

28+
> [!NOTE]
4829
> Known issues (non-exhaustive) with React Native's URL are:
4930
>
5031
> - URL cannot handle "localhost" domain for base url [react-native#26019](https://github.com/facebook/react-native/issues/26019).
5132
> - URL implementation should add a trailing slash to the base [react-native#25717](https://github.com/facebook/react-native/issues/25717).
5233
> - URL incorrectly adds trailing slash [react-native#24428](https://github.com/facebook/react-native/issues/24428).
5334
> - Creating an instance of URL like: `new URL('http://facebook.com')` throws an exception [react-native#16434](https://github.com/facebook/react-native/issues/16434).
5435
55-
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!
36+
That's why you may need this external dependency. If you use [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) within your app, you should look at the installation steps below!
5637

5738
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.
5839

5940
## Installation
6041

61-
First, you need to install the polyfill, which can be done with [Yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/).
62-
63-
#### Yarn
42+
First, you need to install the polyfill, which can be done with [Yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), and others.
6443

6544
```bash
6645
yarn add react-native-url-polyfill
6746
```
6847

69-
#### npm
70-
71-
```bash
72-
npm install --save react-native-url-polyfill
73-
```
74-
7548
Then, the polyfill can be used in multiple ways. Pick your preferred option.
7649

77-
> ℹ️ 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`.
50+
> [!TIP]
51+
> 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`.
7852
7953
### Option 1 (_Simple_)
8054

@@ -90,11 +64,6 @@ import 'react-native-url-polyfill/auto';
9064

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

93-
> ⚠️ Metro doesn't support optional imports.
94-
>
95-
> If you do not apply the polyfill, it will still be added to your JavaScript bundle.
96-
> Even if it's wrapped in a condition, Metro won't strip it in production.
97-
9867
```javascript
9968
import { setupURLPolyfill } from 'react-native-url-polyfill';
10069

0 commit comments

Comments
 (0)