Slice URLs into logical parts - domain, tld or subdomains for node.js
Install by running npm install url-slicer
var urlSlicer = require('url-slicer');
urlSlicer.slice('http://dir.com', function(err, sliced) {
console.log(sliced);
});
Output:
{ domain: 'dir',
tld: 'com',
query: undefined,
subdomains: [] }
Url Slicer is using the public suffix list which can be found here https://publicsuffix.org/list/.
More examples
//http://police.uk
not valid
//http://www.police.uk
{ domain: 'www',
tld: 'police.uk',
query: undefined,
subdomains: [] }
//my.agriculture.museum
{ domain: 'my',
tld: 'agriculture.museum',
query: undefined,
subdomains: [] }
Returns promise when publix suffix list is downloaded and loaded.
Returns object with sliced url data:
{ domain: 'google',
tld: 'com',
query: undefined,
subdomains: [] }
SliceException
is thrown on slice error.