sindresorhus / normalize-url

Normalize a URL
MIT License
837 stars 123 forks source link

Suggestion: keepQueryParameters #172

Closed ozgurg closed 2 years ago

ozgurg commented 2 years ago

Hi. I have a new option suggestion. When we set removeQueryParameters to an array, the package remove query parameters that matches any of the provided strings or regexes. But it would be great if we could reverse this. We will set keepQueryParameters to an array, and the package will only keep that matches any of the provided strings or regexes.

removeQueryParameters:

normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
    removeQueryParameters: ['ref']
});
//=> 'http://sindresorhus.com/?foo=bar'

My suggestion:

normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
    keepQueryParameters: ['ref']
});
//=> 'http://sindresorhus.com/?ref=test_ref'