{"id":13396714,"url":"https://github.com/stevenvachon/relateurl","last_synced_at":"2025-04-05T19:14:22.062Z","repository":{"id":15199857,"uuid":"17928105","full_name":"stevenvachon/relateurl","owner":"stevenvachon","description":"Create a relative URL with options to minify.","archived":false,"fork":false,"pushed_at":"2021-02-27T22:52:28.000Z","size":134,"stargazers_count":56,"open_issues_count":2,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T18:08:37.779Z","etag":null,"topics":["minify","minify-urls","nodejs","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":"2014-03-20T02:28:42.000Z","updated_at":"2025-01-30T17:58:01.000Z","dependencies_parsed_at":"2022-08-25T08:50:09.311Z","dependency_job_id":null,"html_url":"https://github.com/stevenvachon/relateurl","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Frelateurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Frelateurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Frelateurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Frelateurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenvachon","download_url":"https://codeload.github.com/stevenvachon/relateurl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386266,"owners_count":20930619,"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","url","whatwg"],"created_at":"2024-07-30T18:01:00.818Z","updated_at":"2025-04-05T19:14:22.038Z","avatar_url":"https://github.com/stevenvachon.png","language":"JavaScript","funding_links":[],"categories":["路径"],"sub_categories":[],"readme":"# relateurl [![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 Create a relative URL with options to minify.\n\n\nWith `http://domain.com/seg1/seg1-1/` as a base URL, you can produce:\n\n| Before                                     | After                             |\n| :----------------------------------------- | :-------------------------------- |\n| `http://domain.com/seg1/seg1-2/index.html` | `../seg1-2/`                      |\n| `http://domain.com/seg2/seg2-1/`           | `/seg2/seg2-1/`                   |\n| `http://domain.com/seg1/seg1-1/`           | ` `                               |\n| `httpS://domain.com/seg1/seg1-1/`          | `https://domain.com/seg1/seg1-1/` |\n| `../../../../../../../../#anchor`          | `/#anchor`                        |\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 relateurl\n```\n\n\n## Usage\n\nInputs *must* be [`URL`](https://mdn.io/URL) instances.\n\n```js\nconst relateURL = require('relateurl');\n\nconst base = new URL('http://domain.com/seg1/seg1-1/');\nconst url  = new URL('//domain.com/seg1/seg1-2/index.html', base);\n\nrelateURL(url, base, options);\n//-\u003e ../seg1-2/\n```\n\n\n## Options\n\nIt is simplest to use an [option profile](#option-profiles), but custom configurations are still possible.\n\n### `output`\nType: `Symbol`  \nDefault value: `relateURL.SHORTEST`  \nThe limit of how far the resulting URL should be related. Possible values:\n\n* `PROTOCOL_RELATIVE`: will try to produce something like `//domain.com/path/to/file.html`.\n* `ROOT_PATH_RELATIVE`: will try to produce something like `/child-of-root/etc/`.\n* `PATH_RELATIVE`: will try to produce something like `../child-of-parent/etc/`.\n* `SHORTEST`: will try to choose whichever is shortest between `PATH_RELATIVE` and `ROOT_PATH_RELATIVE`.\n\n\n### Minify Options\n\nAny other defined option will be passed to [minurl](https://npmjs.com/minurl). Avoid setting `stringify` to `false`, as it will prevent any operations performed by this library from being outputted.\n\n#### Ignoring Basic Authentication\nIgnoring a URL's username and password attributes will need the not-so-obvious `removeAuth` option (from `minurl`):\n```js\nconst base = new URL('http://user:pass@domain.com/seg1/seg1-1/');\nconst url  = new URL('http://domain.com/seg1/seg1-2/');\n\nrelateURL(url, base, {\n  removeAuth: true\n});\n//-\u003e ../seg1-2/\n````\n\n\n### Option Profiles\n\nThere're two profiles: [`CAREFUL_PROFILE` and `COMMON_PROFILE`](https://npmjs.com/minurl#option-profiles).\n\n\n[npm-image]: https://img.shields.io/npm/v/relateurl.svg\n[npm-url]: https://npmjs.org/package/relateurl\n[filesize-image]: https://img.shields.io/badge/bundle-56kB%20gzipped-blue.svg\n[travis-image]: https://img.shields.io/travis/stevenvachon/relateurl.svg\n[travis-url]: https://travis-ci.org/stevenvachon/relateurl\n[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/relateurl.svg\n[coveralls-url]: https://coveralls.io/github/stevenvachon/relateurl\n[greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/relateurl.svg\n[greenkeeper-url]: https://greenkeeper.io/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Frelateurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenvachon%2Frelateurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Frelateurl/lists"}