{"name":"normalize-url","version":"7.0.2","description":"Normalize a URL","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/normalize-url.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12.20"},"scripts":{"test":"xo && c8 ava && tsd"},"keywords":["normalize","url","uri","address","string","normalization","normalisation","query","querystring","simplify","strip","trim","canonical"],"devDependencies":{"ava":"^3.15.0","c8":"^7.7.3","tsd":"^0.17.0","typescript":"^4.3.5","xo":"^0.41.0"},"c8":{"reporter":["text","lcov"]},"gitHead":"6ea4038783d298d499583db07a820e5ca8ff2721","bugs":{"url":"https://github.com/sindresorhus/normalize-url/issues"},"homepage":"https://github.com/sindresorhus/normalize-url#readme","_id":"normalize-url@7.0.2","_nodeVersion":"14.17.5","_npmVersion":"7.20.3","dist":{"integrity":"sha512-HC9c6eHqxmiR6sL9DKt9ttLkiLaI1jytdkJMGAEvkLAAdlOi99kR7UMWWWRrwjucuFabaau4ZuvP1Zv+6PpDjA==","shasum":"3f250c964484715e6bfbcdfa2524ad76c57e1297","tarball":"http://registry-npm.ywwl.com/normalize-url/download/normalize-url-7.0.2.tgz","fileCount":5,"unpackedSize":22518,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhOv0wCRA9TVsSAnZWagAA64EP/1cpR/4NVsECrPRD8hvT\nUM+9cFw5bZ0cn9v8Eu8e1lXNJXzoz1aUsAW6oRuqy56comYWv/5McvIUZokp\nWOFSPUSzUqNFJOEjpfs84DFJTi8PrqNCRNZu8W7IuWj0iW9Lwl77qW5zOs9b\nsthGiWLO3+sHysoFwovI0OH8MySZ9ufB/pfhW9XCgp5VGW6e7hkPkmp7g318\nka6XImqFez9GBQ217OXVr+NNEcesI1HqrW25NpOtjFMMYdLUt+YQWrqLOZ54\nZvQPRly4xF/Chufzuyu1nk6lJFUbAO84O0xFEGH+QopDKT+ccI+CWWA+rGbn\nFlASO4OQhS4YNpt/xKctKuO/6By8i+zsPGd9pQFZO5Q3beQdgh6nqQS612Xt\nhujblOrMqQBTTwfNh50I7cz9FutpiUDX30AqtmuMMblL727sifgUQQ62dm6P\nwxjl/us4pKkoIChYUo31m9ffdZo4vobh0tc+cj3f7CRy8uR1B570B2ok0zvs\nv02ajQlIbPuLIhTI3zA7MQ/0wod5Y+VyzVNjLTIR6hR7LYWb/tI4jfIZjGOh\n8+T5LQlH7m+hDKCLmOGxQen4ZOJ90jVXOQPKSRsQhkmBKUhriBjaiNWuTJ85\nAPyNEUdBlLjJdpo5yVcrLoysY7I38kQXKsQgDF0cs32OLqx34XeA3E+CqvJJ\n4JXf\r\n=ya+0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAgGsyX2iYc0oHwTM9xAcDF5HPWHZCA3Sjoq1BcAut73AiEA5bUXbBCwrQPxKEJwiDl6K6lZg92fCB2bsM0bYpTpXc8="}],"size":6105,"noattachment":false,"key":"/normalize-url/-/normalize-url-7.0.2.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"},{"name":"kevva","email":"kevinmartensson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/normalize-url_7.0.2_1631255856741_0.5759632105993544"},"_hasShrinkwrap":false,"readme":"# normalize-url [![Coverage Status](https://codecov.io/gh/sindresorhus/normalize-url/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/normalize-url)\n\n> [Normalize](https://en.wikipedia.org/wiki/URL_normalization) a URL\n\nUseful when you need to display, store, deduplicate, sort, compare, etc, URLs.\n\n**Note:** This package does **not** do URL sanitization. [Garbage in, garbage out.](https://en.wikipedia.org/wiki/Garbage_in,_garbage_out) If you use this in a server context and accept URLs as user input, it's up to you to protect against invalid URLs, [path traversal attacks](https://owasp.org/www-community/attacks/Path_Traversal), etc.\n\n## Install\n\n```sh\nnpm install normalize-url\n```\n\n## Usage\n\n```js\nimport normalizeUrl from 'normalize-url';\n\nnormalizeUrl('sindresorhus.com');\n//=> 'http://sindresorhus.com'\n\nnormalizeUrl('//www.sindresorhus.com:80/../baz?b=bar&a=foo');\n//=> 'http://sindresorhus.com/baz?a=foo&b=bar'\n```\n\n## API\n\n### normalizeUrl(url, options?)\n\nURLs with custom protocols are not normalized and just passed through by default. Supported protocols are: `https`, `http`, `file`, and `data`.\n\nHuman-friendly URLs with basic auth (for example, `user:password@sindresorhus.com`) are not handled because basic auth conflicts with custom protocols. [Basic auth URLs are also deprecated.](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#access_using_credentials_in_the_url)\n\n#### url\n\nType: `string`\n\nURL to normalize, including [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs).\n\n#### options\n\nType: `object`\n\n##### defaultProtocol\n\nType: `string`\\\nDefault: `'http'`\\\nValues: `'https' | 'http'`\n\n##### normalizeProtocol\n\nType: `boolean`\\\nDefault: `true`\n\nPrepend `defaultProtocol` to the URL if it's protocol-relative.\n\n```js\nnormalizeUrl('//sindresorhus.com');\n//=> 'http://sindresorhus.com'\n\nnormalizeUrl('//sindresorhus.com', {normalizeProtocol: false});\n//=> '//sindresorhus.com'\n```\n\n##### forceHttp\n\nType: `boolean`\\\nDefault: `false`\n\nNormalize HTTPS to HTTP.\n\n```js\nnormalizeUrl('https://sindresorhus.com');\n//=> 'https://sindresorhus.com'\n\nnormalizeUrl('https://sindresorhus.com', {forceHttp: true});\n//=> 'http://sindresorhus.com'\n```\n\n##### forceHttps\n\nType: `boolean`\\\nDefault: `false`\n\nNormalize HTTP to HTTPS.\n\n```js\nnormalizeUrl('http://sindresorhus.com');\n//=> 'http://sindresorhus.com'\n\nnormalizeUrl('http://sindresorhus.com', {forceHttps: true});\n//=> 'https://sindresorhus.com'\n```\n\nThis option cannot be used with the `forceHttp` option at the same time.\n\n##### stripAuthentication\n\nType: `boolean`\\\nDefault: `true`\n\nStrip the [authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) part of the URL.\n\n```js\nnormalizeUrl('https://user:password@sindresorhus.com');\n//=> 'https://sindresorhus.com'\n\nnormalizeUrl('https://user:password@sindresorhus.com', {stripAuthentication: false});\n//=> 'https://user:password@sindresorhus.com'\n```\n\n##### stripHash\n\nType: `boolean`\\\nDefault: `false`\n\nStrip the hash part of the URL.\n\n```js\nnormalizeUrl('sindresorhus.com/about.html#contact');\n//=> 'http://sindresorhus.com/about.html#contact'\n\nnormalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true});\n//=> 'http://sindresorhus.com/about.html'\n```\n\n##### stripProtocol\n\nType: `boolean`\\\nDefault: `false`\n\nRemove the protocol from the URL: `http://sindresorhus.com` → `sindresorhus.com`.\n\nIt will only remove `https://` and `http://` protocols.\n\n```js\nnormalizeUrl('https://sindresorhus.com');\n//=> 'https://sindresorhus.com'\n\nnormalizeUrl('https://sindresorhus.com', {stripProtocol: true});\n//=> 'sindresorhus.com'\n```\n\n##### stripTextFragment\n\nType: `boolean`\\\nDefault: `true`\n\nStrip the [text fragment](https://web.dev/text-fragments/) part of the URL.\n\n**Note:** The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment.\n\n```js\nnormalizeUrl('http://sindresorhus.com/about.html#:~:text=hello');\n//=> 'http://sindresorhus.com/about.html#'\n\nnormalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello');\n//=> 'http://sindresorhus.com/about.html#section'\n\nnormalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false});\n//=> 'http://sindresorhus.com/about.html#:~:text=hello'\n\nnormalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false});\n//=> 'http://sindresorhus.com/about.html#section:~:text=hello'\n```\n\n##### stripWWW\n\nType: `boolean`\\\nDefault: `true`\n\nRemove `www.` from the URL.\n\n```js\nnormalizeUrl('http://www.sindresorhus.com');\n//=> 'http://sindresorhus.com'\n\nnormalizeUrl('http://www.sindresorhus.com', {stripWWW: false});\n//=> 'http://www.sindresorhus.com'\n```\n\n##### removeQueryParameters\n\nType: `Array<RegExp | string> | boolean`\\\nDefault: `[/^utm_\\w+/i]`\n\nRemove query parameters that matches any of the provided strings or regexes.\n\n```js\nnormalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {\n\tremoveQueryParameters: ['ref']\n});\n//=> 'http://sindresorhus.com/?foo=bar'\n```\n\nIf a boolean is provided, `true` will remove all the query parameters.\n\n```js\nnormalizeUrl('www.sindresorhus.com?foo=bar', {\n\tremoveQueryParameters: true\n});\n//=> 'http://sindresorhus.com'\n```\n\n`false` will not remove any query parameter.\n\n```js\nnormalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {\n\tremoveQueryParameters: false\n});\n//=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'\n```\n\n##### keepQueryParameters\n\nType: `Array<RegExp | string>`\\\nDefault: `undefined`\n\nKeeps only query parameters that matches any of the provided strings or regexes.\n\n**Note:** It overrides the `removeQueryParameters` option.\n\n```js\nnormalizeUrl('https://sindresorhus.com?foo=bar&ref=unicorn', {\n\tkeepQueryParameters: ['ref']\n});\n//=> 'https://sindresorhus.com/?ref=unicorn'\n```\n\n##### removeTrailingSlash\n\nType: `boolean`\\\nDefault: `true`\n\nRemove trailing slash.\n\n**Note:** Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`.\n\n```js\nnormalizeUrl('http://sindresorhus.com/redirect/');\n//=> 'http://sindresorhus.com/redirect'\n\nnormalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false});\n//=> 'http://sindresorhus.com/redirect/'\n\nnormalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false});\n//=> 'http://sindresorhus.com'\n```\n\n##### removeSingleSlash\n\nType: `boolean`\\\nDefault: `true`\n\nRemove a sole `/` pathname in the output. This option is independent of `removeTrailingSlash`.\n\n```js\nnormalizeUrl('https://sindresorhus.com/');\n//=> 'https://sindresorhus.com'\n\nnormalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false});\n//=> 'https://sindresorhus.com/'\n```\n\n##### removeDirectoryIndex\n\nType: `boolean | Array<RegExp | string>`\\\nDefault: `false`\n\nRemoves 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.\n\n```js\nnormalizeUrl('www.sindresorhus.com/foo/default.php', {\n\tremoveDirectoryIndex: [/^default\\.[a-z]+$/]\n});\n//=> 'http://sindresorhus.com/foo'\n```\n\n##### removeExplicitPort\n\nType: `boolean`\\\nDefault: `false`\n\nRemoves an explicit port number from the URL.\n\nPort 443 is always removed from HTTPS URLs and 80 is always removed from HTTP URLs regardless of this option.\n\n```js\nnormalizeUrl('sindresorhus.com:123', {\n\tremoveExplicitPort: true\n});\n//=> 'http://sindresorhus.com'\n```\n\n##### sortQueryParameters\n\nType: `boolean`\\\nDefault: `true`\n\nSorts the query parameters alphabetically by key.\n\n```js\nnormalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', {\n\tsortQueryParameters: false\n});\n//=> 'http://sindresorhus.com/?b=two&a=one&c=three'\n```\n\n## Related\n\n- [compare-urls](https://github.com/sindresorhus/compare-urls) - Compare URLs by first normalizing them\n","publish_time":1631255856896,"_cnpm_publish_time":1631255856896,"dist-tags":{"4-5-1":"4.5.1","5-3-1":"5.3.1","latest":"10.0.0"}}