segmentio / top-domain

Finds the "top" domain for a given URL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

domain

Note
Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.

CircleCI Codecov

Constructs possible levels from a url and attempts to set a cookie "." + domain for each, when it succeeds it returns the top level domain.

This only works on the domain itself, since it attempts to set a cookie.

Installation

$ npm install @segment/top-domain

API

var domain = require('top-domain');

assert('google.com' == domain('http://www.google.com'));
assert('google.co.uk' == domain('http://www.google.co.uk'));
assert('google.co.uk' == domain('http://google.co.uk'));
assert('github.com' == domain('http://gist.github.com/calvinfo/some_file'));
assert('' == domain('http://localhost:3000'));
assert('google.com' == domain('https://google.com:443/stuff'));
assert('' == domain('http://dev:3000'));
assert('' == domain('0.0.0.0'));
assert('' == domain('127.0.0.1'));

About

Finds the "top" domain for a given URL.

License:MIT License


Languages

Language:JavaScript 81.3%Language:Makefile 18.7%