Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 1.94 KB

File metadata and controls

57 lines (40 loc) · 1.94 KB
description
Modern alternatives to uri-js for RFC 3986 URI parsing, resolving, and normalization

Replacements for uri-js

uri-js is unmaintained and triggers deprecation warnings on modern Node.js (due to punycode).

URL (native)

Good for standard web URLs (http/https/ws/wss/file/mailto, etc.).

Example:

import * as URI from 'uri-js' // [!code --]

URI.resolve('https://a/b/c/d?q', '../../g') // [!code --]
new URL('../../g', 'https://a/b/c/d?q').href // [!code ++]

Note

WHATWG URL differs from RFC 3986 in some details and may not cover arbitrary custom schemes/URNs.

uri-js-replace

uri-js-replace is a drop-in, zero-dependency replacement for uri-js with the same API and no deprecation warnings.

import * as URI from 'uri-js' // [!code --]
import * as URI from 'uri-js-replace' // [!code ++]

const parsed = URI.parse('uri://user:pass@example.com:123/one/two?q=a#f')
const out = URI.serialize({
  scheme: 'http',
  host: 'example.com',
  fragment: 'footer'
})
const norm = URI.normalize('URI://www.example.org/red%09ros\xE9#red')

fast-uri

fast-uri is a zero-dependency, high-performance RFC 3986 URI toolbox (parse/serialize/resolve/equal) with options similar to uri-js.

import * as uri from 'uri-js' // [!code --]
import * as uri from 'fast-uri' // [!code ++]

uri.parse('uri://user:pass@example.com:123/one/two.three?q1=a1#a')
uri.serialize({ scheme: 'http', host: 'example.com', fragment: 'footer' })
uri.resolve('uri://a/b/c/d?q', '../../g')
uri.equal('example://a/b/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')