Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

23

index.js

@@ -29,3 +29,3 @@ 'use strict';

function testQueryParameter(name, filters) {
function testParameter(name, filters) {
return filters.some(function (filter) {

@@ -42,3 +42,4 @@ return filter instanceof RegExp ? filter.test(name) : filter === name;

removeQueryParameters: [/^utm_\w+/i],
removeTrailingSlash: true
removeTrailingSlash: true,
removeDirectoryIndex: false
}, opts);

@@ -81,2 +82,18 @@

// remove directory index
if (opts.removeDirectoryIndex === true) {
opts.removeDirectoryIndex = [/^index\.[a-z]+$/];
}
if (Array.isArray(opts.removeDirectoryIndex) && opts.removeDirectoryIndex.length) {
var pathComponents = urlObj.pathname.split('/');
var lastComponent = pathComponents[pathComponents.length - 1];
if (testParameter(lastComponent, opts.removeDirectoryIndex)) {
pathComponents = pathComponents.slice(0, pathComponents.length - 1);
}
urlObj.pathname = pathComponents.slice(1).join('/') + '/';
}
// resolve relative paths, but only for slashed protocols

@@ -112,3 +129,3 @@ if (slashedProtocol[urlObj.protocol]) {

for (var key in queryParameters) {
if (testQueryParameter(key, opts.removeQueryParameters)) {
if (testParameter(key, opts.removeQueryParameters)) {
delete queryParameters[key];

@@ -115,0 +132,0 @@ }

6

package.json
{
"name": "normalize-url",
"version": "1.6.1",
"version": "1.7.0",
"description": "Normalize a URL",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -49,4 +49,4 @@ "scripts": {

"ava": "*",
"xo": "*"
"xo": "^0.16.0"
}
}

@@ -34,3 +34,3 @@ # normalize-url [![Build Status](https://travis-ci.org/sindresorhus/normalize-url.svg?branch=master)](https://travis-ci.org/sindresorhus/normalize-url)

Type: `String`
Type: `string`

@@ -43,3 +43,3 @@ URL to normalize.

Type: `Boolean`<br>
Type: `boolean`<br>
Default: `true`

@@ -59,3 +59,3 @@

Type: `Boolean`<br>
Type: `boolean`<br>
Default: `true`

@@ -75,3 +75,3 @@

Type: `Boolean`<br>
Type: `boolean`<br>
Default: `true`

@@ -91,3 +91,3 @@

Type: `Array<RegExp|String>`<br>
Type: `Array<RegExp|string>`<br>
Default: `[/^utm_\w+/i]`

@@ -124,3 +124,17 @@

##### removeDirectoryIndex
Type: `boolean` `Array<RegExp|string>`<br>
Default: `false`
Remove the default directory index file from path that matches any of the provided strings or regexes. When `true`, the regex `/^index\.[a-z]+$/` is used.
```js
normalizeUrl('www.sindresorhus.com/foo/default.php', {
removeDirectoryIndex: [/^default\.[a-z]+$/]
});
//=> 'http://sindresorhus.com/foo'
```
## Related

@@ -127,0 +141,0 @@

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