get-link
v1.0.4
Published
Returns a new, absolute URL by parsing the link relative to the base URL. Supports dynamic links. Not vulnerable to Denial-of-Service attacks.
Downloads
42
Maintainers
Readme
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 protected]");
// => http://example.com
getLink("http://example.com", "http://domain.com");
// => false
Tests
$ npm test