Skip to content

Slice URLs into logical parts - domain, tld or subdomains for node.js

License

Notifications You must be signed in to change notification settings

nacholibre/url-slicer.js

Repository files navigation

Build Status

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.

About

Slice URLs into logical parts - domain, tld or subdomains for node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published