Socket
Socket
Sign inDemoInstall

parse-domain

Package Overview
Dependencies
10
Maintainers
10
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-beta.10 to 3.0.0

12

CHANGELOG.md

@@ -0,1 +1,13 @@

# [3.0.0](https://github.com/peerigon/parse-domain/compare/v2.3.4...v3.0.0) (2020-04-23)
### Features
* Complete rewrite in TypeScript and several bug fixes and improvements ([9f38492](https://github.com/peerigon/parse-domain/commit/9f384921015ab962975ae1d3833507dd7ec0cc52))
### BREAKING CHANGES
* This release is a complete rewrite in TypeScript. It fixes some long outstanding bugs and comes with improvements we were planning for quite some time. The major changes are: 1. parseDomain does not accept whole URLs anymore. Only the hostname section of a URL is allowed now. 2. We removed the options object. Custom TLDs are returned as "valid but not listed". The parse result contains both the result with private TLDs and without private TLDs. 3. Dropped Node 6 support. We recommend reading the README since the public API as changed quite a lot.
# [3.0.0-beta.10](https://github.com/peerigon/parse-domain/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2020-04-23)

@@ -2,0 +14,0 @@

2

package.json
{
"name": "parse-domain",
"version": "3.0.0-beta.10",
"version": "3.0.0",
"description": "Splits a hostname into subdomains, domain and (effective) top-level domains",

@@ -5,0 +5,0 @@ "keywords": [

# parse-domain
**Splits a hostname into subdomains, domain and (effective) top-level domains. Written in TypeScript.**
**Splits a hostname into subdomains, domain and (effective) top-level domains.**

@@ -10,6 +10,7 @@ [![Version on NPM](https://img.shields.io/npm/v/parse-domain?style=for-the-badge)](https://www.npmjs.com/package/parse-domain)

[![Known Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/parse-domain?style=for-the-badge)](https://snyk.io/test/github/peerigon/parse-domain)
![Written in TypeScript](https://img.shields.io/npm/types/parse-domain?style=for-the-badge)
[![Coverage Status](https://img.shields.io/coveralls/github/peerigon/parse-domain?style=for-the-badge)](https://coveralls.io/github/peerigon/parse-domain?branch=master)
[![License](https://img.shields.io/npm/l/parse-domain?style=for-the-badge)](https://unlicense.org/)
Since domain name registrars organize their namespaces in different ways, it's not straight-forward to split a hostname into subdomains, the domain and top-level domains. **parse-domain** validates the given hostname against [RFC 1034](https://tools.ietf.org/html/rfc1034) and uses a [large list of known top-level domains](https://publicsuffix.org/list/public_suffix_list.dat) from publicsuffix.org to do that:
Since domain name registrars organize their namespaces in different ways, it's not straight-forward to split a hostname into subdomains, the domain and top-level domains. In order to do that **parse-domain** uses a [large list of known top-level domains](https://publicsuffix.org/list/public_suffix_list.dat) from [publicsuffix.org](https://publicsuffix.org/):

@@ -30,5 +31,5 @@ ```javascript

This package has been designed for modern Node and browser environments. It assumes an ES2015 environment with `Symbol()` and the global [`URL` constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL) available. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments.
This package has been designed for modern Node and browser environments, supporting both CommonJS and ECMAScript modules. It assumes an ES2015 environment with [`Symbol()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) and [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL) globally available. You need to transpile it down to ES5 (e.g. by using [Babel](https://babeljs.io/)) if you need to support older environments.
The list of top-level domains is stored in a [trie](https://en.wikipedia.org/wiki/Trie) data structure and serialization format to ensure the fastest lookup and the smallest possible library size. The library is roughly 30KB minified and gzipped.
The list of top-level domains is stored in a [trie](https://en.wikipedia.org/wiki/Trie) data structure and serialization format to ensure the fastest lookup and the smallest possible library size. The library is roughly 30KB minified and gzipped and is side-effect free (this is important for proper [tree-shaking](https://webpack.js.org/guides/tree-shaking/)).

@@ -45,3 +46,3 @@ <br />

💡 **Please note:** publicsuffix.org is updated several times per month. This package comes with a prebuilt list that has been downloaded at the time of `npm publish`. In order to get an up-to-date list, you should run `npx parse-domain-update` everytime you start or build your application. This will download the latest list from `https://publicsuffix.org/list/public_suffix_list.dat`.
💡 **Please note:** [publicsuffix.org](https://publicsuffix.org/) is updated several times per month. This package comes with a prebuilt list that has been downloaded at the time of `npm publish`. In order to get an up-to-date list, you should run `npx parse-domain-update` everytime you start or build your application. This will download the latest list from `https://publicsuffix.org/list/public_suffix_list.dat`.

@@ -79,3 +80,3 @@ <br />

[`fromUrl`](#api-js-fromUrl) uses the `URL` constructor under the hood. Depending on your target environments you need to make sure that there is a polyfill for it. It's globally available in [all modern browsers](https://caniuse.com/#feat=url) (no IE) and in [Node v10](https://nodejs.org/api/url.html#url_class_url).
[`fromUrl`](#api-js-fromUrl) parses the URL using [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL). Depending on your target environments you need to make sure that there is a [polyfill](https://www.npmjs.com/package/whatwg-url) for it. It's globally available in [all modern browsers](https://caniuse.com/#feat=url) (no IE) and in [Node v10](https://nodejs.org/api/url.html#url_class_url).

@@ -87,7 +88,7 @@ ## Expected output

- invalid
- it is an IPv4 or IPv6 address
- formally correct and the domain
- is reserved
- is not listed in the public suffix list
- is listed
- it is an ip address
- it is formally correct and the domain is
- reserved
- not listed in the public suffix list
- listed in the public suffix list

@@ -123,3 +124,3 @@ [`parseDomain`](#api-js-parseDomain) returns a [`ParseResult`](#api-ts-ParseResult) with a `type` property that allows to distinguish these cases.

It's debatable if a library for parsing domains should also accept IP addresses. In fact, you could argue that [`parseDomain`](#api-js-parseDomain) should reject an IP address as invalid domain. While this is true from a technical point of view, we decided to report IP addresses in a special way because we assume that a lot of people are using this library to make sense out of a hostname (see [#102](https://github.com/peerigon/parse-domain/issues/102)).
It's debatable if a library for parsing domains should also accept IP addresses. In fact, you could argue that [`parseDomain`](#api-js-parseDomain) should reject an IP address as invalid. While this is true from a technical point of view, we decided to report IP addresses in a special way because we assume that a lot of people are using this library to make sense from an arbitrary hostname (see [#102](https://github.com/peerigon/parse-domain/issues/102)).

@@ -173,3 +174,3 @@ ### 👉 Reserved domains

- `co` in `example.co`
- `com.co` in `example.com.co`
- but also `com.co` in `example.com.co`

@@ -221,5 +222,5 @@ If the hostname is listed in the public suffix list, the `parseResult.type` will be `ParseResultType.Listed`:

### ⚠️ Effective top-level domains vs. ICANN
### ⚠️ Effective TLDs !== TLDs acknowledged by ICANN
What's surprising to a lot of people is that the definition of public suffix means that regular business domains can become effective top-level domains:
What's surprising to a lot of people is that the definition of public suffix means that regular user domains can become effective top-level domains:

@@ -236,5 +237,5 @@ ```javascript

In this case `github.io` is nothing else than a private domain name registrar. `github.io` is the _effective_ top-level domain and browsers are treating it like that.
In this case, `github.io` is nothing else than a private domain name registrar. `github.io` is the _effective_ top-level domain and browsers are treating it like that (e.g. for setting [`document.domain`](https://developer.mozilla.org/en-US/docs/Web/API/Document/domain)).
If you're only interested in top-level domains listed in the [ICANN](https://en.wikipedia.org/wiki/ICANN) section of the public suffix list, there's an `icann` property:
If you want to deviate from the browser's understanding of a top-level domain and you're only interested in top-level domains acknowledged by [ICANN](https://en.wikipedia.org/wiki/ICANN), there's an `icann` property:

@@ -282,3 +283,3 @@ ```javascript

Takes a hostname (e.g. `"www.example.com"`) and returns a [`ParseResult`](#api-ts-ParseResult). The hostname must only contain letters, digits, hyphens and dots. International hostnames must be puny-encoded. Does not throw an error, even with invalid input.
Takes a hostname (e.g. `"www.example.com"`) and returns a [`ParseResult`](#api-ts-ParseResult). The hostname must only contain basic latin characters, digits, hyphens and dots. International hostnames must be puny-encoded. Does not throw an error, even with invalid input.

@@ -295,3 +296,3 @@ ```javascript

Takes a URL-like string and tries to extract the hostname. Requires the global [`URL` constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL) to be available on the platform. Returns the [`NO_HOSTNAME`](#api-js-NO_HOSTNAME) symbol if the input was not a string or the hostname could not be extracted. Take a look [at the test suite](/blob/master/src/from-url.test.ts) for some examples. Does not throw an error, even with invalid input.
Takes a URL-like string and tries to extract the hostname. Requires the global [`URL` constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL) to be available on the platform. Returns the [`NO_HOSTNAME`](#api-js-NO_HOSTNAME) symbol if the input was not a string or the hostname could not be extracted. Take a look [at the test suite](/src/from-url.test.ts) for some examples. Does not throw an error, even with invalid input.

@@ -308,7 +309,7 @@ <h3 id="api-js-NO_HOSTNAME">

A `ParseResult` is either a [`ParseResultInvalid`](#api-ts-ParseResultInvalid), [`ParseResultReserved`](#api-ts-ParseResultReserved), [`ParseResultNotListed`](#api-ts-ParseResultNotListed) or [`ParseResultListed`](#api-ts-ParseResultListed).
A `ParseResult` is either a [`ParseResultInvalid`](#api-ts-ParseResultInvalid), [`ParseResultIp`](#api-ts-ParseResultIp), [`ParseResultReserved`](#api-ts-ParseResultReserved), [`ParseResultNotListed`](#api-ts-ParseResultNotListed) or [`ParseResultListed`](#api-ts-ParseResultListed).
All parse results have a `type` property that is either `"INVALID"`, `"RESERVED"`, `"NOT_LISTED"` or `"LISTED"`. Use the exported [ParseResultType](#api-js-ParseResultType) to check for the type instead of checking against string literals.
All parse results have a `type` property that is either `"INVALID", "IP",`"RESERVED"`,`"NOT_LISTED"`or`"LISTED"`. Use the exported [ParseResultType](#api-js-ParseResultType) to check for the type instead of checking against string literals.
All parse results also have a `hostname` property that stores the original hostname that was passed to [`parseDomain`](#api-js-parseDomain).
All parse results also have a `hostname` property that provides access to the sanitized hostname that was passed to [`parseDomain`](#api-js-parseDomain).

@@ -347,3 +348,3 @@ <h3 id="api-js-ParseResultType">

- A domain label is longer than 63 characters
- A domain label contains a character that is not a letter, digit or hyphen
- A domain label contains a character that is not a basic latin character, digit or hyphen

@@ -471,3 +472,3 @@ ```ts

Describes the shape of the parse result that is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the public suffix list.
Describes the shape of the parse result that is returned when the given hostname is valid and does not belong to a reserved top-level domain, but is not listed in the downloaded public suffix list.

@@ -474,0 +475,0 @@ ```ts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc