get-link

1.0.4 • Public • Published

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

Package Sidebar

Install

npm i get-link

Weekly Downloads

5

Version

1.0.4

License

MIT

Unpacked Size

14.7 kB

Total Files

12

Last publish

Collaborators

  • bartozzz