get-link

Returns a new, absolute URL by parsing the link relative to the base URL. Supports dynamic links. Not vulnerable to Denial-of-Service attacks.

Usage no npm install needed!

<script type="module">
  import getLink from 'https://cdn.skypack.dev/get-link';
</script>

README

get-link

Greenkeeper badge Build Status License npm version npm downloads

Returns an absolute URL relative to another URL. Not vulnerable to Denial-of-Service attacks.

Installation

$ npm install get-link

Usage

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

import getLink from "get-link";

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

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

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

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

getLink("http://example.com", "#dynamic-website");
// => http://example.com

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

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

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

Tests

$ npm test