summaryrefslogtreecommitdiffstats
path: root/lib/utils/location.js
blob: efe1425a17a9b901d52f49a217c0b423ae0c4cf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
}

// Return true if the link is an achor
function isAnchor(href) {
    try {
        var parsed = url.parse(href);
        return !!(!parsed.protocol && !parsed.path && parsed.hash);
    } catch(err) {
        return false;
    }
}

module.exports = {
    isExternal: isExternal,
    isRelative: isRelative,
    isAnchor: isAnchor
};