Skip to content

Latest commit

 

History

History
62 lines (51 loc) · 1.2 KB

README.md

File metadata and controls

62 lines (51 loc) · 1.2 KB

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.