normalize-url 6.0.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -155,8 +155,26 @@ declare namespace normalizeUrl {
155
155
  });
156
156
  //=> 'http://sindresorhus.com/?foo=bar'
157
157
  ```
158
+
159
+ If a boolean is provided, `true` will remove all the query parameters.
160
+
161
+ ```
162
+ normalizeUrl('www.sindresorhus.com?foo=bar', {
163
+ removeQueryParameters: true
164
+ });
165
+ //=> 'http://sindresorhus.com'
166
+ ```
167
+
168
+ `false` will not remove any query parameter.
169
+
170
+ ```
171
+ normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
172
+ removeQueryParameters: false
173
+ });
174
+ //=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
175
+ ```
158
176
  */
159
- readonly removeQueryParameters?: ReadonlyArray<RegExp | string>;
177
+ readonly removeQueryParameters?: ReadonlyArray<RegExp | string> | boolean;
160
178
 
161
179
  /**
162
180
  Removes trailing slash.
package/index.js CHANGED
@@ -173,6 +173,10 @@ const normalizeUrl = (urlString, options) => {
173
173
  }
174
174
  }
175
175
 
176
+ if (options.removeQueryParameters === true) {
177
+ urlObj.search = '';
178
+ }
179
+
176
180
  // Sort query parameters
177
181
  if (options.sortQueryParameters) {
178
182
  urlObj.searchParams.sort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "normalize-url",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "Normalize a URL",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/normalize-url",
package/readme.md CHANGED
@@ -175,7 +175,7 @@ normalizeUrl('http://www.sindresorhus.com', {stripWWW: false});
175
175
 
176
176
  ##### removeQueryParameters
177
177
 
178
- Type: `Array<RegExp | string>`\
178
+ Type: `Array<RegExp | string> | boolean`\
179
179
  Default: `[/^utm_\w+/i]`
180
180
 
181
181
  Remove query parameters that matches any of the provided strings or regexes.
@@ -187,6 +187,24 @@ normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
187
187
  //=> 'http://sindresorhus.com/?foo=bar'
188
188
  ```
189
189
 
190
+ If a boolean is provided, `true` will remove all the query parameters.
191
+
192
+ ```js
193
+ normalizeUrl('www.sindresorhus.com?foo=bar', {
194
+ removeQueryParameters: true
195
+ });
196
+ //=> 'http://sindresorhus.com'
197
+ ```
198
+
199
+ `false` will not remove any query parameter.
200
+
201
+ ```js
202
+ normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
203
+ removeQueryParameters: false
204
+ });
205
+ //=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
206
+ ```
207
+
190
208
  ##### removeTrailingSlash
191
209
 
192
210
  Type: `boolean`\