{"id":15814322,"url":"https://github.com/stevenvachon/minurl","last_synced_at":"2025-03-14T20:32:03.775Z","repository":{"id":54324562,"uuid":"83161046","full_name":"stevenvachon/minurl","owner":"stevenvachon","description":"Reduce and normalize the components of a WHATWG URL.","archived":false,"fork":false,"pushed_at":"2021-02-27T22:51:00.000Z","size":16,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T00:17:31.265Z","etag":null,"topics":["minify","minify-urls","nodejs","normalize","url","whatwg"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevenvachon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-25T20:36:54.000Z","updated_at":"2024-03-27T14:26:34.000Z","dependencies_parsed_at":"2022-08-13T12:01:03.907Z","dependency_job_id":null,"html_url":"https://github.com/stevenvachon/minurl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fminurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fminurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fminurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fminurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenvachon","download_url":"https://codeload.github.com/stevenvachon/minurl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243051711,"owners_count":20228250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["minify","minify-urls","nodejs","normalize","url","whatwg"],"created_at":"2024-10-05T04:24:11.276Z","updated_at":"2025-03-14T20:32:03.506Z","avatar_url":"https://github.com/stevenvachon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# minurl [![NPM Version][npm-image]][npm-url] ![File Size][filesize-image] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Monitor][greenkeeper-image]][greenkeeper-url]\n\n\u003e Reduce and normalize the components of a [`URL`](https://mdn.io/URL).\n\n\n## Installation\n\n[Node.js](https://nodejs.org) `\u003e= 14` is required. To install, type this at the command line:\n```shell\nnpm install minurl\n```\n\n\n## Usage\n```js\nconst minURL = require('minurl');\n\nconst url = new URL('http://www.domain.com/index.html?param1=va%20lue\u0026param2=');\n\nminURL(url, options);\n//-\u003e http://domain.com?param1=va+lue\u0026param2\n```\n\n**Note:** \"www\" subdomains and \"index.html\" indexes are *not* part of *any* specification. They are merely a common configuration on many HTTP servers. Consider this when deciding on which options to use.\n\n\n## Options\n\nIt is simplest to use an [option profile](#option-profiles), but custom configurations are still possible.\n\n### `clone`\nType: `Boolean`  \nDefault value: `true`  \nWhen set to `true`, the input `URL` will first be cloned before any changes are made. When set to `false`, the input `URL` will be mutated.\n\n### `defaultPorts`\nType: `Object`  \nDefault value: `{'ftps:':990, 'git:':9418, 'scp:':22, 'sftp:':22, 'ssh:':22}`  \nA map of protocol default ports for [`removeDefaultPort`](#removedefaultport). Be sure to include the suffixed \":\" in the key. [Common protocols](https://url.spec.whatwg.org/#special-scheme) already have their ports removed.\n\n### `indexFilenames`\nType: `Array\u003cRegExp|string\u003e`  \nDefault value: `['index.html']`  \nA list of file names for [`removeIndexFilename`](#removeindexfilename).\n\n### `plusQueries`\nType: `Boolean` or `Function`  \nDefault value: `true`  \nWhen set to `true` or a function that returns `true`, a URL will use \"+\" instead of \"%20\" to encode spaces in query parameter names and values.\n\n### `queryNames`\nType: `Array\u003cRegExp|string\u003e`  \nDefault value: `[]`  \nA list of query parameters for [`removeQueryNames`](#removequerynames).\n\n### `removeAuth`\nType: `Boolean` or `Function`  \nDefault value: `false`  \nWhen set to `true` or a function that returns `true`, a URL's username and password will be removed.\n\n### `removeDefaultPort`\nType: `Boolean` or `Function`  \nDefault value: `true`  \nWhen set to `true` or a function that returns `true`, a URL's port that matches any found in [`defaultPorts`](#defaultports) will be removed.\n\n### `removeEmptyHash`\nType: `Boolean` or `Function`  \nDefault value: `true`  \nWhen set to `true` or a function that returns `true`, a URL hash value of \"#\" will be removed.\n\n### `removeEmptyQueries`\nType: `Boolean` or `Function`  \nDefault value: [`Function`](https://github.com/stevenvachon/minurl/blob/master/src/minurl.js#L101-L104)  \nWhen set to `true` or a function that returns `true`, a URL's empty query parameters (such as \"?=\") will be removed.\n\n### `removeEmptyQueryNames`\nType: `Boolean` or `Function`  \nDefault value: [`Function`](https://github.com/stevenvachon/minurl/blob/master/src/minurl.js#L94-L97)  \nWhen set to `true` or a function that returns `true`, a URL's query parameters that contain a value with no name (such as \"?=value\") will be removed.\n\n### `removeEmptyQueryValues`\nType: `Boolean` or `Function`  \nDefault value: [`Function`](https://github.com/stevenvachon/minurl/blob/master/src/minurl.js#L94-L97)  \nWhen set to `true` or a function that returns `true`, a URL's query parameters that contain no value (such as \"?var=\" and \"?var\") will be removed.\n\n### `removeEmptySegmentNames`\nType: `Boolean` or `Function`  \nDefault value: `false`  \nWhen set to `true` or a function that returns `true`, empty segment names within a URL's path will be removed. For example, the \"//\" in \"/path//to/\" will become \"/path/to/\". Protocol-relative URLs will not be affected.\n\n### `removeHash`\nType: `Boolean` or `Function`  \nDefault value: `false`  \nWhen set to `true` or a function that returns `true`, a URL's hash will be removed.\n\n### `removeIndexFilename`\nType: `Boolean` or `Function`  \nDefault value: [`Function`](https://github.com/stevenvachon/minurl/blob/master/src/minurl.js#L87-L90)  \nWhen set to `true` or a function that returns `true`, a URL's file name that matches any found in [`indexFilenames`](#indexfilenames) will be removed.\n\n### `removeQueryNames`\nType: `Boolean` or `Function`  \nDefault value: `false`  \nWhen set to `true` or a function that returns `true`, a URL's query parameters matching [`queryNames`](#querynames) will be removed.\n\n### `removeQueryOddities`\nType: `Boolean` or `Function`  \nDefault value: `true`  \nWhen set to `true` or a function that returns `true`, a URL's unnecessary occurrences of \"?\", \"=\" and \"\u0026\" characters will be removed.\n\n### `removeRootTrailingSlash`\nType: `Boolean` or `Function`  \nDefault value: `true`  \nWhen set to `true` or a function that returns `true`, a URL's *root* trailing slash (such as `http://domain.com/?var`) will be removed.\n\n### `removeTrailingSlash`\nType: `Boolean` or `Function`  \nDefault value: `false`  \nWhen set to `true` or a function that returns `true`, *any* trailing slash in a URL (such as `http://domain.com/dir/`) will be removed.\n\n### `removeWWW`\nType: `Boolean` or `Function`  \nDefault value: [`Function`](https://github.com/stevenvachon/minurl/blob/master/src/minurl.js#L87-L90)  \nWhen set to `true` or a function that returns `true`, a URL's \"www\" subdomain will be removed.\n\n### `sortQueries`\nType: `Boolean` or `Function`  \nDefault value: [`Function`](https://github.com/stevenvachon/minurl/blob/master/src/minurl.js#L101-L104)  \nWhen set to `true` or a function that returns `true`, a URL's query parameters will be sorted alphanumerically.\n\n### `stringify`\nType: `Boolean`  \nDefault value: `true`  \nWhen set to `true`, a string will be returned. When set to `false`, a `URL` will be returned. Beware that the [`removeRootTrailingSlash`](#removeroottrailingslash) and [`removeTrailingSlash`](#removetrailingslash) options can only be applied when this option is set to `true`.\n\n\n### Option as a Function\n\nWhen an option is defined as a `Function`, it must return `true` to be included in the custom filter:\n```js\nconst options = {\n  removeIndexFilename: url =\u003e {\n    // Only URLs with these protocols will have their index filename removed\n    return url.protocol === 'http:' \u0026\u0026 url.protocol === 'https:';\n  }\n};\n```\n\n\n### Option Profiles\n\n`CAREFUL_PROFILE` is useful for a URL to an unknown or third-party server that could be incorrectly configured according to specifications and common best practices.\n\n`COMMON_PROFILE`, the default profile, is useful for a URL to a known server that you trust and expect to be correctly configured according to specifications and common best practices.\n\nAn example of checking for a trusted hostname:\n```js\nconst profile = url =\u003e {\n  const trustedHosts = ['domain.com'];\n\n  const isTrusted = trustedHosts.some(trustedHost =\u003e {\n    return url.hostname === trustedHost || url.hostname.endsWith(`.${trustedHost}`);\n  });\n\n  return minURL[`${isTrusted ? 'COMMON' : 'CAREFUL'}_PROFILE`];\n};\n\nconst url1 = new URL('http://www.domain.com/index.html?param1=va%20lue\u0026param2=');\nconst url2 = new URL('http://www.fake-domain.com/index.html?param1=va%20lue\u0026param2=');\n\nminURL(url1, profile(url1));  // will use \"common\" profile\nminURL(url2, profile(url2));  // will use \"careful\" profile\n```\n\n\n#### Customizing Profiles\n\n```js\nconst custom = {\n  ...minURL.COMMON_PROFILE,\n  indexFilenames: ['index.html', 'index.php']\n};\n```\nOr:\n```js\nconst extend = require('extend');\n\nconst custom = extend(true, {}, minURL.COMMON_PROFILE, { indexFilenames:['index.php'] });\n```\n\n\n[npm-image]: https://img.shields.io/npm/v/minurl.svg\n[npm-url]: https://npmjs.com/package/minurl\n[filesize-image]: https://img.shields.io/badge/bundle-40kB%20gzipped-blue.svg\n[travis-image]: https://img.shields.io/travis/stevenvachon/minurl.svg\n[travis-url]: https://travis-ci.org/stevenvachon/minurl\n[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/minurl.svg\n[coveralls-url]: https://coveralls.io/github/stevenvachon/minurl\n[greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/minurl.svg\n[greenkeeper-url]: https://greenkeeper.io/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fminurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenvachon%2Fminurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fminurl/lists"}