normalize-url
Advanced tools
Comparing version 5.3.0 to 6.0.0
@@ -107,2 +107,26 @@ declare namespace normalizeUrl { | ||
/** | ||
Strip the [text fragment](https://web.dev/text-fragments/) part of the URL | ||
__Note:__ The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment. | ||
@default true | ||
@example | ||
``` | ||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello'); | ||
//=> 'http://sindresorhus.com/about.html#' | ||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello'); | ||
//=> 'http://sindresorhus.com/about.html#section' | ||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false}); | ||
//=> 'http://sindresorhus.com/about.html#:~:text=hello' | ||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false}); | ||
//=> 'http://sindresorhus.com/about.html#section:~:text=hello' | ||
``` | ||
*/ | ||
readonly stripTextFragment?: boolean; | ||
/** | ||
Removes `www.` from the URL. | ||
@@ -109,0 +133,0 @@ |
@@ -70,2 +70,3 @@ 'use strict'; | ||
stripHash: false, | ||
stripTextFragment: true, | ||
stripWWW: true, | ||
@@ -122,2 +123,4 @@ removeQueryParameters: [/^utm_\w+/i], | ||
urlObj.hash = ''; | ||
} else if (options.stripTextFragment) { | ||
urlObj.hash = urlObj.hash.replace(/#?:~:text.*?$/i, ''); | ||
} | ||
@@ -124,0 +127,0 @@ |
{ | ||
"name": "normalize-url", | ||
"version": "5.3.0", | ||
"version": "6.0.0", | ||
"description": "Normalize a URL", | ||
@@ -11,3 +11,3 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
@@ -41,7 +41,12 @@ "engines": { | ||
"ava": "^2.4.0", | ||
"coveralls": "^3.0.6", | ||
"nyc": "^15.0.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.3" | ||
}, | ||
"nyc": { | ||
"reporter": [ | ||
"text", | ||
"lcov" | ||
] | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# normalize-url [![Build Status](https://travis-ci.org/sindresorhus/normalize-url.svg?branch=master)](https://travis-ci.org/sindresorhus/normalize-url) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/normalize-url/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/normalize-url?branch=master) | ||
# normalize-url [![Coverage Status](https://codecov.io/gh/sindresorhus/normalize-url/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/normalize-url) | ||
@@ -138,2 +138,25 @@ > [Normalize](https://en.wikipedia.org/wiki/URL_normalization) a URL | ||
##### stripTextFragment | ||
Type: `boolean`\ | ||
Default: `true` | ||
Strip the [text fragment](https://web.dev/text-fragments/) part of the URL. | ||
**Note:** The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment. | ||
```js | ||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello'); | ||
//=> 'http://sindresorhus.com/about.html#' | ||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello'); | ||
//=> 'http://sindresorhus.com/about.html#section' | ||
normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false}); | ||
//=> 'http://sindresorhus.com/about.html#:~:text=hello' | ||
normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false}); | ||
//=> 'http://sindresorhus.com/about.html#section:~:text=hello' | ||
``` | ||
##### stripWWW | ||
@@ -236,3 +259,2 @@ | ||
--- | ||
@@ -239,0 +261,0 @@ |
20253
4
356
269