3.0.2 • Published 2 years ago

get-base-url v3.0.2

Weekly downloads
50
License
ISC
Repository
github
Last release
2 years ago

Get base url

Deprecated: This library was created due to me being unaware of the existence of the WHATWG URL API. As it is widely supported in both browsers and node and probably more accurate, I see no need for this anymore.

Get the host of an arbitrary url - relative or absulute or static. Suited for comparison with location.host to inquire whether an url is in local domain scope.

Usage

import getBaseUrl from "get-base-url"
const { getBaseUrl } = require("get-base-url")

getBaseUrl("https://maps.google.com/sub/")   // maps.google.com
getBaseUrl("maps.google.com/sub")            // maps.google.com
getBaseUrl("google.com")                     // google.com
getBaseUrl()                                 // The current host if in a browser or localhost of in node
getBaseUrl("relative")                       // The current host if in a browser or localhost of in node
getBaseUrl("./relative")                     // The current host if in a browser or localhost of in node
getBaseUrl("/absolute")                      // The current host if in a browser or localhost of in node

Compare whether arbitrary url is in local domain scope

import getBaseUrl from "get-base-url"
const { getBaseUrl } = require("get-base-url")

function isLocalUrl(url) {
  return getBaseUrl(url) === getBaseUrl()
}

isLocalUrl("sub")           // true
isLocalUrl("google.com")    // false
isLocalUrl("/google.com")   // true
3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

3 years ago

2.2.0

3 years ago

2.1.10

3 years ago

2.1.9

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.4

3 years ago

2.1.5

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago