Skip to content

Normalizes URL's to prevent duplicates that point to the same server resource

Notifications You must be signed in to change notification settings

QubitProducts/url-canon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-canon

Normalizes URL's to prevent duplicates that point to the same server resource.

var urlCanon = require('url-canon')
urlCanon('https://www.google.com/?b=hey&a=yo&#')
// => returns 'https://www.google.com/?&a=yo&b=hey'

Installation

npm install url-canon

Features

  • Sorts query parameters into alphabetical order
  • Decodes needlessly percent-encoded ASCII
  • Removes default ports for http/https
  • Lowercases the protocol and hostname
  • Removes trailing # and ?
  • Uppercases percent encoded bytes

Compatibility

Tests pass in

  • IE8+
  • Chrome
  • Firefox
  • Opera

Does not support Node.js (as it uses an anchor element for parsing).

Known issues

Internationalised URLs such as https://見.香港/ are converted to punycode form in Chrome but not in Firefox and IE. Conversely punycode such as https://xn--nw2a.xn--j6w193g/ is decoded automatically in Firefox and IE to https://見.香港/. It is very hard to standardise these URLs and they have not been handled.

About

Normalizes URL's to prevent duplicates that point to the same server resource

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published