url-slicer
v1.0.0
Published
Slice URLs into logical parts - domain, tld or subdomains
Downloads
9
Maintainers
Readme
url-slicer.js
Slice URLs into logical parts - domain, tld or subdomains for node.js
Installation
Install by running npm install url-slicer
Usage
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: [] }
API
urlSlicer.init()
Returns promise when publix suffix list is downloaded and loaded.
urlSlicer.slice(url)
Returns object with sliced url data:
{ domain: 'google',
tld: 'com',
query: undefined,
subdomains: [] }
SliceException
is thrown on slice error.