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.
$ npm install get-link
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 protected]");
// => 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
$ npm test