Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

normalize-url

Package Overview
Dependencies
Maintainers
2
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-url

Normalize a URL

  • 1.6.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is normalize-url?

The normalize-url npm package is used to normalize and sanitize URLs to ensure they have a standard and consistent format. It can be used to remove tracking parameters, sort query parameters, remove default ports, and more.

What are normalize-url's main functionalities?

Normalizing URLs

This feature allows you to normalize a URL by converting it to a standard format. It can remove or add 'http://', sort query parameters, and convert the hostname to lowercase.

"use strict";
const normalizeUrl = require('normalize-url');

console.log(normalizeUrl('sindresorhus.com')); // Output: 'http://sindresorhus.com'
console.log(normalizeUrl('HTTP://xn--xample-hva.com:80/?b=bar&a=foo')); // Output: 'http://êxample.com/?a=foo&b=bar'"

Removing URL Tracking Parameters

This feature allows you to remove URL tracking parameters like 'utm_source' and 'utm_medium' by using a regular expression.

"use strict";
const normalizeUrl = require('normalize-url');

console.log(normalizeUrl('www.sindresorhus.com?utm_source=foo&utm_medium=bar', {removeQueryParameters: [/^utm_/]})); // Output: 'http://sindresorhus.com'"

Removing Default Ports

This feature removes the default ports from URLs (port 80 for HTTP and port 443 for HTTPS).

"use strict";
const normalizeUrl = require('normalize-url');

console.log(normalizeUrl('http://sindresorhus.com:80')); // Output: 'http://sindresorhus.com'
console.log(normalizeUrl('https://sindresorhus.com:443')); // Output: 'https://sindresorhus.com'"

Forcing HTTPS

This feature allows you to force the URL to use HTTPS instead of HTTP.

"use strict";
const normalizeUrl = require('normalize-url');

console.log(normalizeUrl('http://sindresorhus.com', {forceHttps: true})); // Output: 'https://sindresorhus.com'"

Other packages similar to normalize-url

Keywords

FAQs

Package last updated on 02 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc