uri-js is a comprehensive JavaScript library designed for parsing, validating, resolving, normalizing, and comparing URIs and IRIs, strictly adhering to RFC 3986 (URI) and RFC 3987 (IRI) specifications. It also incorporates support for IDNA (RFC 5890), IPv6 Address (RFC 5952), and IPv6 Zone Identifier (RFC 6874). The current stable version is 4.4.1. The library is actively maintained, with a focus on robust RFC compliance and broad environment compatibility (browsers, Node.js). Key differentiators include its scheme-extendable architecture, extensive test suite, and compact size (6.4kb gzipped, 17kb deflated), making it a reliable choice for applications requiring precise URI manipulation without significant overhead. It offers granular control over parsing and serialization through an extensive options object.
npm install uri-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionalities of URI.js including parsing, serializing, resolving, normalizing, and comparing URIs, alongside its specific support for Internationalized Resource Identifiers (IRIs).
Pass `{ tolerant: true }` as an option to parsing functions: `URI.parse(uriString, { tolerant: true })`.For IRI output, use `URI.serialize(parsedObject, { iri: true })`. For parsing with unicode support, use `URI.parse(iriString, { unicodeSupport: true })`.Ensure the '%' character in an IPv6 zone identifier is encoded as `%25`. For example, `//[fe80::1%25en0]` instead of `//[fe80::1%en0]`.
Use `URI.equal()` for comparison where possible, as it accounts for these normalizations. If manually comparing, apply normalization first or be aware of standard port elision and case insensitivity for certain URI components.
Use `import * as URI from 'uri-js';` for ESM or `const URI = require('uri-js');` for CommonJS environments.Review the URI string for syntax errors. If parsing non-standard or 'dirty' URIs, consider using the `{ tolerant: true }` option: `URI.parse(uriString, { tolerant: true })`.Ensure all necessary URI components (e.g., `scheme`, `host` for absolute URIs) are provided and correctly formatted in the object passed to `URI.serialize` or `URI.build` (if using an extended API).
No dependency data recorded yet.