{"c8":{"reporter":["text","lcov"]},"xo":[{"rules":{"unicorn/prefer-https":"off","node-test/no-conditional-assertion":"off"}},{"files":"test.js","rules":{"unicorn/no-break-in-nested-loop":"off"}}],"_id":"normalize-url@10.0.0","bugs":{"url":"https://github.com/sindresorhus/normalize-url/issues"},"dist":{"shasum":"901999a7c56da2721a3fbd98dde47b2aef5547e4","tarball":"http://registry-npm.ywwl.com/normalize-url/download/normalize-url-10.0.0.tgz","fileCount":5,"integrity":"sha512-aZEiiOP3lVdNrCCdPELWvJHbjJjoPfbWRLPAZLSsGA6l4ckvPmZSB+uX6JB4QQu33SeXCsd6v75jKivr43n/EQ==","signatures":[{"sig":"MEQCIC0+0clVMq1ZkFWzWcysyrvXs+MktSnaNrvnukQfWETbAiBbYxFoWKcmw1mfbs1ZAR4hgEUypaqCZZwvGQSN6BMm6A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC686m2ZMBAHkGJetdzZ8d4bAZOlNRqhDv4cQxBJ1qKwQIgJwjg4BdzdgE8GTUihOaX4OHISPHPY0NvqS4RkL4EjTw="}],"unpackedSize":72495,"size":18375,"noattachment":false,"key":"/normalize-url/-/normalize-url-10.0.0.tgz"},"name":"normalize-url","type":"module","types":"./index.d.ts","author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"engines":{"node":">=22"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"5d0151dd3a702f96becc90241331259d5642b735","license":"MIT","scripts":{"test":"xo && node --test"},"version":"10.0.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"homepage":"https://github.com/sindresorhus/normalize-url#readme","keywords":["normalize","url","uri","address","string","normalization","normalisation","query","querystring","simplify","strip","trim","canonical"],"repository":{"url":"git+https://github.com/sindresorhus/normalize-url.git","type":"git"},"_npmVersion":"12.2.0","description":"Normalize a URL","directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"sideEffects":false,"_nodeVersion":"26.11.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^5.0.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/normalize-url_10.0.0_1791998732603_0.2314820094957628"},"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]\n> 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`. Use the [`customProtocols`](#customprotocols) option to add support for additional protocols.\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__Note:__ a scheme with a dot in it followed by `//` is a custom protocol, so it is passed through as well and nothing in the URL is normalized. `example.com/path` is a host and gets `http:` prepended, but `example.com://host/path` is a scheme named `example.com` and is left alone. Use the [`customProtocols`](#customprotocols) option to normalize one on purpose.\n\nWhatever the options, a normalized URL also gets these changes:\n\n- Tab, carriage return, and line feed are removed from anywhere, as a URL parser does. Whitespace and C0 controls are removed from the ends, including U+00A0 and a byte order mark, which are often left over from copying a URL. Other whitespace inside the URL is kept, and escaped where a URL parser escapes it.\n- A URL parser lowercases the protocol. For a built-in protocol, it also lowercases the host, converts an internationalized host to Punycode, resolves `.` and `..` path segments, and removes a default port.\n- Trailing dots are removed from a domain host, unless that changes the name: `159.189.213..` keeps them, since `159.189.213` is the IPv4 address `159.189.0.213`. The host of a custom protocol is opaque, so its dots are kept.\n- Duplicate slashes in the path are removed, except the two of a protocol-like segment such as `/https://`.\n- Percent escapes are uppercased (`%2f` → `%2F`), except in the media type of a data URL, where percent-looking text is literal MIME content. Escapes of unreserved characters (letters, digits, `-`, `.`, `_`, `~`) are decoded (`%7E` → `~`), except in a fragment, the media type of a data URL, the host of a custom protocol, and a path that does not start with `/`. Fragment escapes stay encoded so they cannot become text directives. The path and the query also decode other escapes where the character means the same unescaped, as in `%5B` → `[`. Escapes that would change the structure, like `%2F`, `%3F`, `%23`, and `%26`, stay escaped, so `%2F` and `/` stay different.\n- The query is written the way `URLSearchParams` writes it: a space in a value is `+`, a space in a key is `%20`, a `?` is `%3F`, and a `%` that starts no escape is `%25`. Empty parameters, as in `?a=1&&b=2`, are removed. This happens with `sortQueryParameters: false` too. An escape that is not valid UTF-8 becomes U+FFFD, as `URLSearchParams` decodes it, so `?q=%E9` becomes `?q=%EF%BF%BD`, which changes the value for a server that reads the query as Latin-1.\n- A data URL gets its MIME type and `charset` value lowercased. `text/plain` is removed when nothing follows it, and so is `charset=us-ascii` on `text/plain`. Quotes are removed from a parameter value that does not need them, and whitespace is removed from the ends of base64 data.\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'`\n\nUsually `'https'` or `'http'`. A trailing `:` is accepted. A value that is not a scheme, such as `'https://'`, throws a `TypeError`.\n\n__Note:__ A protocol that is not built in, such as `'ftp'`, is best-effort. The URL it creates is normalized, while the same URL written with that protocol is passed through as a custom protocol, unless the protocol is in `customProtocols`.\n\n##### customProtocols\n\nType: `string[]`\\\nDefault: `undefined`\n\nProtocols to normalize in addition to the built-in ones (`https`, `http`, `file`, `data`).\n\nUseful for HTTP-like custom protocols such as Electron schemes or app-specific protocols.\n\nThe protocols should be specified without `:`, though a trailing one is accepted. The name is case-insensitive.\n\n__Note:__ Options that rewrite the path (`removePath`, `transformPath`, `removeDirectoryIndex`, and the percent-decoding of the path) only apply when the path starts with a `/`, as in `sindre://host/a/b` and `sindre:/a/b`. A URL whose path is opaque, such as `sindre:a/b`, has no segments for those options to work on, and a URL parser does not let the library change it, so they are silently ignored for it.\n\n__Note:__ `transformPath` and `removeDirectoryIndex` rebuild the path from its components, which cannot spell the two slashes of a protocol lookalike such as `sindre://host/a/s3://b/index.html`. One of them is dropped for those two options, while the library keeps both everywhere else.\n\n```js\nnormalizeUrl('sindre://www.sorhus.com', {customProtocols: ['sindre']});\n//=> 'sindre://sorhus.com'\n\nnormalizeUrl('sindre://www.sorhus.com/foo/', {customProtocols: ['sindre']});\n//=> 'sindre://sorhus.com/foo'\n```\n\n##### normalizeProtocol\n\nType: `boolean`\\\nDefault: `true`\n\nPrepend `defaultProtocol` to the URL if it's protocol-relative.\n\nWith `false`, a protocol-relative URL stays protocol-relative, even with `defaultProtocol` or `forceHttps` set.\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__Note:__ changing the scheme drops the port that was the default one for the old scheme, so `forceHttp` turns `https://example.com:443` into `http://example.com` and `forceHttps` turns `http://example.com:80` into `https://example.com`. A port that is not a default for either scheme is kept.\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__Note:__ changing the scheme drops the port that was the default one for the old scheme, so `forceHttp` turns `https://example.com:443` into `http://example.com` and `forceHttps` turns `http://example.com:80` into `https://example.com`. A port that is not a default for either scheme is kept.\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 removes an `https://`, an `http://` or a leading `//` from a protocol-relative URL, and nothing else.\n\n__Note:__ The result is not a full URL, so normalizing it again can change it: a port that the removed protocol kept is the default one of the protocol that gets prepended next.\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__Note:__ A `www.` that is not followed by a proper domain is left alone, so `www.com` and `www.a.b` are not changed.\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. The match is against the percent-decoded key, the way `URLSearchParams` reads one, so `+` is a space and `%2F` is a slash: write `a/b` rather than `a%2Fb`.\n\nGlobal and sticky regex flags are stripped.\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://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. The match is against the percent-decoded key, the same as `removeQueryParameters`. An empty array matches nothing, so it removes every parameter, the same as the `true` of `removeQueryParameters`.\n\n**Note:** It overrides the `removeQueryParameters` option.\n\nGlobal and sticky regex flags are stripped.\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:** the sole `/` of a root path is removed too, unless the `removeSingleSlash` option is set to `false` **and** the input wrote that slash itself.\n\n__Note:__ `removeSingleSlash: false` reads the trailing slash off the input as it was written, so a slash that belongs to a dot segment a URL parser resolves away still counts. `https://example.com/a/../` and `https://example.com/a/..` are the same URL, but only the first keeps the root slash.\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\nThe `/` is kept when a query or a hash follows it, as in `https://sindresorhus.com/?a=1`.\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. The match is against the percent-decoded component, the same as `transformPath` is given, so `index.html` matches a path spelled `index%2Ehtml`. It runs after `transformPath`, so it also removes an index file the function leaves at the end.\n\nWhen `true`, the regex `/^index\\.[a-z]+$/` is used.\n\n__Note:__ removing the index leaves a trailing slash on what is left, whether or not the input wrote one, so `http://example.com/foo/index.html` becomes `http://example.com/foo/` and then `http://example.com/foo`. The `removeTrailingSlash` option decides whether that slash stays.\n\nGlobal and sticky regex flags are stripped.\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 by key, in code unit order, so an uppercase letter sorts before a lowercase one and a digit before a letter. Parameters that share a key keep the order they were written in.\n\n__Note:__ The option only changes the order. The query is written the same way either way (see [`normalizeUrl`](#normalizeurlurl-options)).\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##### emptyQueryValue\n\nType: `string`\\\nDefault: `'preserve'`\\\nValues: `'preserve' | 'always' | 'never'`\n\nControls how query parameters with empty values are formatted.\n\n- `'preserve'` - Keep the original format (`?key` stays `?key`, `?key=` stays `?key=`). If the same key appears with both formats (`?a&a=`), all instances will use the format without `=`.\n- `'always'` - Always include `=` for empty values (`?key` becomes `?key=`)\n- `'never'` - Never include `=` for empty values (`?key=` becomes `?key`)\n\n```js\nnormalizeUrl('www.sindresorhus.com?a&b=', {emptyQueryValue: 'always'});\n//=> 'http://sindresorhus.com/?a=&b='\n\nnormalizeUrl('www.sindresorhus.com?a&b=', {emptyQueryValue: 'never'});\n//=> 'http://sindresorhus.com/?a&b'\n```\n\n##### removePath\n\nType: `boolean`\\\nDefault: `false`\n\nRemoves the entire URL path, leaving the host with no path. The query and the hash stay. It takes precedence over the `transformPath` option.\n\n```js\nnormalizeUrl('https://example.com/path/to/page', {\n\tremovePath: true\n});\n//=> 'https://example.com'\n```\n\n##### transformPath\n\nType: `Function | false`\\\nDefault: `false`\n\nCustom function to transform the URL path components. The function receives an array of non-empty path components and should return a modified array. Returning nothing removes the path. The components are percent-decoded, so an unreserved escape has become the character it stands for by the time the function sees it, and one it returns is not decoded again. It runs before `removeDirectoryIndex`, so the function still sees the index file, and it is skipped when `removePath` is set.\n\n```js\n// Keep only the first path component\nnormalizeUrl('https://example.com/api/v1/users', {\n\ttransformPath: (pathComponents) => pathComponents.slice(0, 1)\n});\n//=> 'https://example.com/api'\n\n// Remove specific components\nnormalizeUrl('https://example.com/admin/users', {\n\ttransformPath: (pathComponents) => pathComponents.filter(c => c !== 'admin')\n});\n//=> 'https://example.com/users'\n```\n\n## Related\n\n- [compare-urls](https://github.com/sindresorhus/compare-urls) - Compare URLs by first normalizing them\n","publish_time":1791998732695,"_cnpm_publish_time":1791998732695,"dist-tags":{"4-5-1":"4.5.1","5-3-1":"5.3.1","latest":"10.0.0"}}