Skip to content

stevenvachon/universal-url-lite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

universal-url-lite NPM Version Build Status Dependency Monitor

A smaller Universal WHATWG URL, for Browserify/etc.

The universal-url package bundles to 392kB (99kB gzipped). This package exists to compile the same to a smaller file size via custom optimizations.

This package is not meant to be required/imported directly. It should be added to your browser build process as an alias.

Installation

Node.js >= 6 is required. To install, type this at the command line:

npm install universal-url-lite

Default Shim File Size File Size

Usage:

"browser": {
  "universal-url": "universal-url-lite"
}

File size optimizations have been made, particularly the near-complete exclusion of the TR46 implementation. Functionality is essentially the same as the universal-url package, with the exception of IDNA validation and normalization. If a URL contains a hostname with any of the ~4500 Unicode characters requiring a specific casefold, comparison will produce false negatives. Consider this example:

const url1 = new URL('http://ㅼㅼㅼ/');
const url2 = new URL('http://ᄯᄯᄯ/');

console.log(url1.hostname === url2.hostname);
//-> false -- which is incorrect

With invalid IDNAs passing through without error, you will instead need to rely on errors produced by XMLHttpRequest/fetch to know that such URLs are unreachable.

Note: You will need to exclude this browser shim from bundle parsing since it has already been compiled. Browserify has the --noparse CLI option and Webpack has the noParse package.json key.

browserify in.js --outfile=out.js --noparse='/project/node_modules/universal-url-lite/lite.js'

"Native" Shim File Size

This actually includes no shim at all for browser builds. Only the latest browsers will be supported.

Usage:

"browser": {
  "universal-url": "universal-url-lite/native"
}

Releases

No releases published

Packages

No packages published