parse-domain
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -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) |
"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 @@ |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
613847
6
33
1066
139
5
1
6
2
+ Addedchai@^4.1.2
+ Addedfs-copy-file-sync@^1.1.1
+ Addedgot@^8.0.1
+ Addedmkdirp@^0.5.1
+ Addedmocha@^4.0.1
+ Added@sindresorhus/is@0.7.0(transitive)
+ Addedassertion-error@1.1.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbrowser-stdout@1.3.0(transitive)
+ Addedcacheable-request@2.1.4(transitive)
+ Addedchai@4.4.1(transitive)
+ Addedcheck-error@1.0.3(transitive)
+ Addedclone-response@1.0.2(transitive)
+ Addedcommander@2.11.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@3.1.0(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddeep-eql@4.1.4(transitive)
+ Addeddiff@3.3.1(transitive)
+ Addedduplexer3@0.1.5(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfrom2@2.3.0(transitive)
+ Addedfs-copy-file-sync@1.1.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedglob@7.1.2(transitive)
+ Addedgot@8.3.2(transitive)
+ Addedgrowl@1.10.3(transitive)
+ Addedhas-flag@2.0.0(transitive)
+ Addedhas-symbol-support-x@1.4.2(transitive)
+ Addedhas-to-string-tag-x@1.4.1(transitive)
+ Addedhe@1.1.1(transitive)
+ Addedhttp-cache-semantics@3.8.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinto-stream@3.1.0(transitive)
+ Addedis-object@1.0.2(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedis-retry-allowed@1.2.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisurl@1.0.0(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.0.0(transitive)
+ Addedloupe@2.3.7(transitive)
+ Addedlowercase-keys@1.0.01.0.1(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@0.0.81.2.8(transitive)
+ Addedmkdirp@0.5.10.5.6(transitive)
+ Addedmocha@4.1.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addednormalize-url@2.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-cancelable@0.4.1(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-is-promise@1.1.0(transitive)
+ Addedp-timeout@2.0.1(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpathval@1.1.1(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedquery-string@5.1.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedsort-keys@2.0.0(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsupports-color@4.4.0(transitive)
+ Addedtimed-out@4.0.1(transitive)
+ Addedtype-detect@4.0.8(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
+ Addedurl-to-options@1.0.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)