From dc03bb9ec740e4e03a620562e3e66e70f31410b0 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Sat, 28 May 2016 11:11:50 -0700 Subject: [PATCH] add function to convert host parameters to hostname --- lib/to-host.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/to-host.js diff --git a/lib/to-host.js b/lib/to-host.js new file mode 100644 index 0000000..0474409 --- /dev/null +++ b/lib/to-host.js @@ -0,0 +1,17 @@ +import { parse } from 'url'; + +/** + * Converts a valid deployment lookup parameter to a hostname. + * `http://google.com` => google.com + * google.com => google.com + */ + +export default function toHost (url) { + if (/^https?:\/\//.test(url)) { + return parse(url).host; + } else { + // remove any path if present + // `a.b.c/` => `a.b.c` + return url.replace(/(\/\/)?([^\/]+)(.*)/, '$2'); + } +}