diff options
Diffstat (limited to 'lib/utils/location.js')
-rw-r--r-- | lib/utils/location.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/utils/location.js b/lib/utils/location.js new file mode 100644 index 0000000..d57e84f --- /dev/null +++ b/lib/utils/location.js @@ -0,0 +1,21 @@ +var url = require('url'); + +// Is the url an external url +function isExternal(href) { + try { + return Boolean(url.parse(href).protocol); + } catch(err) { + return false; + } +} + + +// Inverse of isExternal +function isRelative(href) { + return !isExternal(href); +} + +module.exports = { + isExternal: isExternal, + isRelative: isRelative +}; |