Skip to content

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.

License

Notifications You must be signed in to change notification settings

Bartozzz/get-link

Repository files navigation

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

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •