Socket
Socket
Sign inDemoInstall

parse-domain

Package Overview
Dependencies
76
Maintainers
8
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

build/tries/pre/icann.complete.json

10

CHANGELOG.md

@@ -5,2 +5,12 @@ # Change Log

<a name="2.1.0"></a>
# [2.1.0](https://github.com/peerigon/parse-domain/compare/v2.0.0...v2.1.0) (2018-05-30)
### Features
* Use trie data structure to decrease file size ([#33](https://github.com/peerigon/parse-domain/issues/33)) ([59f951b](https://github.com/peerigon/parse-domain/commit/59f951b))
<a name="2.0.0"></a>

@@ -7,0 +17,0 @@ # [2.0.0](https://github.com/peerigon/parse-domain/compare/v1.2.0...v2.0.0) (2017-12-03)

27

lib/parseDomain.js
"use strict";
const knownTlds = require("./tld.js");
const normalize = require("./normalize.js");
const lookUp = require("./tries/lookUp");
const icannTrie = require("../lists/icann.complete");
const privateTrie = require("../lists/private.complete");
const urlParts = /^(https?:\/\/)?([^/]*@)?(.+?)(:\d{2,5})?([/?].*)?$/; // 1 = protocol, 2 = auth, 3 = domain, 4 = port, 5 = path
const dot = /\./g;
const emptyArr = [];
function matchTld(domain, options) {
let tld = null;
// for potentially unrecognized tlds, try matching against custom tlds
if (options.customTlds) {
// try matching against a built regexp of custom tlds
tld = domain.match(options.customTlds);
const tld = domain.match(options.customTlds);
if (tld !== null) {
return tld[0];
}
}
// If no custom tlds, check if tld is supported
if (tld === null) {
tld = domain.match(options.privateTlds ? knownTlds : knownTlds.icann);
if (tld === null) {
return null;
const tries = (options.privateTlds ? [privateTrie] : emptyArr).concat(icannTrie);
for (const trie of tries) {
const tld = lookUp(trie, domain);
if (tld !== null) {
return "." + tld;
}
}
return tld[0];
return null;
}

@@ -28,0 +35,0 @@

{
"name": "parse-domain",
"version": "2.0.0",
"version": "2.1.0",
"description": "Splits an url into sub-domain, domain and effective top-level-domain",

@@ -9,5 +9,3 @@ "main": "./lib/parseDomain.js",

"posttest": "eslint lib test",
"download-tld": "curl https://publicsuffix.org/list/public_suffix_list.dat > lib/build/tld.txt",
"build-regex": "node lib/build/buildRegex.js",
"update-regex": "npm run download-tld && npm run build-regex && npm run test",
"postinstall": "node scripts/build-tries.js",
"release": "standard-version"

@@ -32,5 +30,10 @@ },

"license": "Unlicense",
"dependencies": {},
"dependencies": {
"chai": "^4.1.2",
"fs-copy-file-sync": "^1.1.1",
"got": "^8.0.1",
"mkdirp": "^0.5.1",
"mocha": "^4.0.1"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.12.1",

@@ -40,3 +43,2 @@ "eslint-config-peerigon": "^12.0.1",

"eslint-plugin-jsdoc": "^3.2.0",
"mocha": "^4.0.1",
"nyc": "^11.3.0",

@@ -46,4 +48,8 @@ "standard-version": "^4.2.0"

"files": [
"lib"
"lib",
"scripts",
"lists",
"test",
"build/tries/pre"
]
}

@@ -13,2 +13,4 @@ parse-domain

This module uses a [trie](https://en.wikipedia.org/wiki/Trie) data structure under the hood to ensure the smallest possible library size and the fastest lookup. The library is roughly 30KB minified and gzipped. Since publicsuffix.org is frequently updated, the data structure is built on `npm install` as a `postinstall` hook. If something goes wrong during that step, the library falls back to a prebuilt list that has been built at the time of publishing.
<br />

@@ -20,3 +22,3 @@

```sh
npm install --save parse-domain
npm install parse-domain
```

@@ -23,0 +25,0 @@

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