Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 17 days 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 8 years ago)
- Default Branch: development
- Last Pushed: 2023-01-07T03:55:36.000Z (almost 2 years ago)
- Last Synced: 2024-10-06T13:48:11.638Z (about 1 month 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
[![Default CI/CD](https://github.com/Bartozzz/get-link/workflows/Default%20CI/CD/badge.svg)](https://github.com/Bartozzz/get-link/actions)
[![Known Vulnerabilities](https://snyk.io/test/github/Bartozzz/get-link/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Bartozzz/get-link?targetFile=package.json)
[![npm package size](https://img.badgesize.io/Bartozzz/get-link/master/dist/index.js?compression=gzip)](https://www.npmjs.com/package/get-link)
[![npm version](https://img.shields.io/npm/v/get-link.svg)](https://www.npmjs.com/package/get-link)
[![npm dependency Status](https://david-dm.org/Bartozzz/get-link.svg)](https://www.npmjs.com/package/get-link)
[![npm downloads](https://img.shields.io/npm/dt/get-link.svg)](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 protected]");
// => 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
```