Skip to content

Latest commit

 

History

History
executable file
·
51 lines (36 loc) · 1.73 KB

README.md

File metadata and controls

executable file
·
51 lines (36 loc) · 1.73 KB

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