https://github.com/bartozzz/get-link
Builds an absolute URL based on an absolute base URL and a link. Makes sure that both base and link are valid, on the same host and HTTP/HTTPS protocol. Stripes hashes. WHATWG URL compatible.
https://github.com/bartozzz/get-link
absolute-url helper link path relative-path url utility
Last synced: 6 months ago
JSON representation
Builds an absolute URL based on an absolute base URL and a link. Makes sure that both base and link are valid, on the same host and HTTP/HTTPS protocol. Stripes hashes. WHATWG URL compatible.
- Host: GitHub
- URL: https://github.com/bartozzz/get-link
- Owner: Bartozzz
- License: mit
- Created: 2016-04-09T14:17:58.000Z (over 9 years ago)
- Default Branch: development
- Last Pushed: 2023-01-07T03:55:36.000Z (over 2 years ago)
- Last Synced: 2025-02-22T18:48:16.595Z (8 months ago)
- Topics: absolute-url, helper, link, path, relative-path, url, utility
- Language: JavaScript
- Homepage: https://npmjs.com/package/get-link
- Size: 1.34 MB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
get-link
[](https://github.com/Bartozzz/get-link/actions)
[](https://snyk.io/test/github/Bartozzz/get-link?targetFile=package.json)
[](https://www.npmjs.com/package/get-link)
[](https://www.npmjs.com/package/get-link)
[](https://www.npmjs.com/package/get-link)
[](https://www.npmjs.com/package/get-link)`get-link` builds an absolute URL based on an absolute `base` URL and a `link`. Makes sure that both `base` and `link` are valid, on the same host and HTTP/HTTPS protocol. Stripes hashes. [WHATWG URL](https://url.spec.whatwg.org/) compatible.
## Installation
```bash
$ npm install get-link
```## Usage
`getLink(base: string, link: string): string`
```javascript
import getLink from "get-link";getLink("http://example.com", "/foo.html#hash");
getLink("http://example.com", "http://example.com/foo.html#hash");
// => http://example.com/foo.htmlgetLink("http://example.com", "javascript:void(0)");
getLink("http://example.com", "mailto:email@example.com");
// => http://example.comgetLink("http://example.com/some/deep/path", "../../styles");
// => http://example.com/stylesgetLink("http://example.com", "http://domain.com");
// => http://example.comgetLink("invalid base");
// => TypeError
```## Tests
```bash
$ npm test
```