react-native-url-polyfill

repository·main·Indexed 19 days ago

https://github.com/charpeni/react-native-url-polyfill

A lightweight, WHATWG-compliant URL polyfill for React Native version 4.0.0. It provides a reliable implementation of URL and URLSearchParams supporting Hermes, Expo, and Blob. The library can be applied automatically via 'react-native-url-polyfill/auto', manually using setupURLPolyfill(), or used as a ponyfill by importing classes directly. Note: Non-ASCII characters are not supported in hostnames.

Tokens
3.1K
Snippets
13
Records
17
Agent score
65%

What's inside react-native-url-polyfill

  1. Build and run the iOS app

    main

    To run the iOS application, you must first ensure CocoaPods dependencies are installed.

    1. Install CocoaPods dependencies:

      • If this is your first time or you have updated native dependencies, run:
        bundle exec pod install
      • If you are setting up the Ruby environment for the first time, run:
        bundle install
    2. Run the app:

      # Using npm
      npm run ios
      
      # OR using Yarn
      yarn ios
    bundle exec pod install
    # THEN
    npm run ios
    # OR
    yarn ios
  2. Apply the polyfill automatically (Simple)

    main

    To automatically apply the polyfill globally, import react-native-url-polyfill/auto at the very top of your JavaScript entry-point file (usually index.js). This method is the simplest way to ensure URL and URLSearchParams are available throughout your application.

    Note: On web platforms, this import acts as a no-op.

    import 'react-native-url-polyfill/auto';
  3. Use as a ponyfill (Convenient)

    main

    If you do not want to overwrite the default React Native URL implementation, you can use this library as a ponyfill by importing the specific classes you need. This allows you to use the WHATWG-compliant implementation alongside the existing global URL.

    import { URL, URLSearchParams } from 'react-native-url-polyfill';
    
    const url = new URL('https://github.com');
    const searchParams = new URLSearchParams('q=GitHub');
  4. Reload your application to see changes

    main

    After modifying your code (e.g., in App.tsx), you can reload the application to apply changes using the following platform-specific methods:

    • Android: Press the <kbd>R</kbd> key twice or open the Developer Menu (<kbd>Ctrl</kbd> + <kbd>M</kbd> on Windows/Linux or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> on macOS) and select "Reload".
    • iOS: Press <kbd>Cmd ⌘</kbd> + <kbd>R</kbd> in the iOS Simulator.