# @segment/top-domain

> Finds the top domain for a URL

Latest version **3.0.1** (published 2021-04-14) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @segment/top-domain
pnpm add @segment/top-domain
yarn add @segment/top-domain
bun add @segment/top-domain
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2021-04-14 |
| First published | 2016-05-19 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Segment |
| Maintainers | gilomer, anna.choi, alistairbarrell, odoren, arta.razavi, kelcook, gnijor, lauramunozjimenez, parsa-segment, ynguyen, mshwery, flaque, gpsamson, amillet89, av-segment, scruwys1, rowno, chenpengcheng, segmentaimee, eesegment, segmentio, segment-admin, dominicbarnes, ladanazita, anoonan, peripheral, achille-roussel, nettofarah, albert.segment, segment-danielstjules, jlee9595, n2parko, segment-andy-yeo, sahilp, vdemedes, emilio-gomez-lavin, f2prateek, andreiko_ru, xagos, emily.luckette, leifdreizler, alan-segment, tyson_segment, bgamwell, jfabre-segment, uditmehta, hellooimkat, brienne.mcnally, sanscontext, eculver, aultimus, erikdw, fauzyy, jaimal, davidbirdsong, ktrinh, calthomson, yunqiaohuang, dk1027, nickatsegment, nielssegment, knoonan, cdrycroft, yabrira, shse, julee05, kamebkj, ryan_segment, laurenmreeder, tidothegreat, mericsson, prayansh-segmentt, stargaesser, andyguwc, jeremylarkin, bsneed, danieljackins, tomeliaz, segment-seth, xav_segment, bihl, shamil.ataev, james9446, priscilla.giatti, kellylu, smokeybears, jmbuckner, benhorowitz, yolken-segment, nlsun, thomas-pelletier-segment, brian-segment, segment-michael, cohara87, osamakhn, drew-thompson, andy-li, segment-jsingh, vanesng, cvillela, pauljaeinyoo, stevenmiller888, mniehe, iajiboye, stephment, sharadbhadouria, emilyc, maggieyu, anoonan16, durgani, colinlohner, julio.farah, hblanks-segment, rsata, shyaan, juhaelee, akleiner2, kathryn-taylor, andrius-segment, pooyaj, llbsgmt, lab176, valerieernst, emilyluckette, ucarion, solon.aguiar, rjenkinsseg, segment-ulysse, khinkalilover, maloneya, zackurey |
| Keywords | domain, top-domain |

## Links

- npm: https://www.npmjs.com/package/@segment/top-domain
- Repository: https://github.com/segmentio/top-domain
- Homepage: https://github.com/segmentio/top-domain#readme
- Issues: https://github.com/segmentio/top-domain/issues
- npm.io page: https://npm.io/package/@segment/top-domain

## Dependencies (2)

- [component-url](https://npm.io/package/component-url.md) ^0.2.1
- [component-cookie](https://npm.io/package/component-cookie.md) ^1.1.5

## Recent versions

- 3.0.1 (latest) — 2021-04-14
- 3.0.0 — 2016-05-19

## README

# domain

[![CircleCI](https://circleci.com/gh/segmentio/top-domain.svg?style=shield&circle-token=a8809ce04276a1cb738c1818284155be3021a7dc)](https://circleci.com/gh/segmentio/top-domain)
[![Codecov](https://img.shields.io/codecov/c/github/segmentio/top-domain/master.svg?maxAge=2592000)](https://codecov.io/gh/segmentio/top-domain)

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

```sh
$ npm install @segment/top-domain
```

## API

```js
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'));
```

---
_Source: https://npm.io/package/@segment/top-domain · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
