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.

Home Page:https://npmjs.com/package/get-link

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get-link

Default CI/CD Known Vulnerabilities npm package size npm version npm dependency Status npm downloads

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.

Installation

$ npm install get-link

Usage

getLink(base: string, link: string): string

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.html

getLink("http://example.com", "javascript:void(0)");
getLink("http://example.com", "mailto:email@example.com");
// => http://example.com

getLink("http://example.com/some/deep/path", "../../styles");
// => http://example.com/styles

getLink("http://example.com", "http://domain.com");
// => http://example.com

getLink("invalid base");
// => TypeError

Tests

$ npm test

About

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://npmjs.com/package/get-link

License:MIT License


Languages

Language:JavaScript 100.0%