Socket
Socket
Sign inDemoInstall

extract-domain

Package Overview
Dependencies
1
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 4.1.0

dist/index.d.ts

2

dist/extract-domain.modern.js

@@ -1,2 +0,2 @@

function r(){throw new TypeError("The given URL is not a string. Please verify your string|array.")}const t=["/",":","?","#"],e=[".","/","@"];function n(n,o){"string"!=typeof n&&r();let i=0,s=0,f=0,l=0,a=n.length,c=0;for(;a--&&++c&&!(i&&t.indexOf(n[c])>-1);)"."===n[c]&&(++i,s=c);for(l=c,c=s;c--;)if(-1!==e.indexOf(n[c])){f=c+1;break}if(0===f&&l>3)return n;if(f>0&&f<2)return"";if(o.tld){let r=0;const t=["/","@"];let e=s;for(;e--;)if(t.indexOf(n[e])>-1){r=e+1;break}try{return import("psl").then(t=>Promise.resolve(t.get(n.slice(r,l)))).catch(console.error)}catch(r){throw console.error(r),Error("You must install psl library (https://www.npmjs.com/package/psl) to use `tld` option")}}return n.slice(f,l)}function o(t,e={}){if("string"==typeof t)return n(t,e);if(Array.isArray(t)){const r=[],o=t.length;let i=0;for(;i<o;i++)r.push(n(t[i],e));return r}r()}export{o as default};
const r=["/",":","?","#"],t=[".","/","@"];function e(e,n){let o=0,i=0,s=0,f=0,l=e.length,a=0;for(;l--&&++a&&!(o&&r.indexOf(e[a])>-1);)"."===e[a]&&(++o,i=a);for(f=a,a=i;a--;)if(-1!==t.indexOf(e[a])){s=a+1;break}if(0===s&&f>3)return e;if(s>0&&s<2)return"";if(n.tld){let r=0;const t=["/","@"];let n=i;for(;n--;)if(t.indexOf(e[n])>-1){r=n+1;break}return import("psl").then(t=>Promise.resolve(t.get(e.slice(r,f)))).catch(r=>{throw console.error(r),Error("You must install psl library (https://www.npmjs.com/package/psl) to use `tld` option")})}return e.slice(s,f)}function n(r,t={}){if("string"==typeof r)return e(r,t);if(Array.isArray(r)){const n=[],o=r.length;let i=0;for(;i<o;i++){const o=e(r[i],t);n.push(o)}return n}!function(){throw new TypeError("The given URL is not a string. Please verify your string|array.")}()}export{n as default};
//# sourceMappingURL=extract-domain.modern.js.map

@@ -1,2 +0,2 @@

function r(){throw new TypeError("The given URL is not a string. Please verify your string|array.")}var e=["/",":","?","#"],t=[".","/","@"];function n(n,o){"string"!=typeof n&&r();for(var i,s=0,f=0,a=0,l=n.length,u=0;l--&&++u&&!(s&&e.indexOf(n[u])>-1);)"."===n[u]&&(++s,f=u);for(i=u,u=f;u--;)if(-1!==t.indexOf(n[u])){a=u+1;break}if(0===a&&i>3)return n;if(a>0&&a<2)return"";if(o.tld){for(var c=0,p=["/","@"],h=f;h--;)if(p.indexOf(n[h])>-1){c=h+1;break}try{return import("psl").then(function(r){return Promise.resolve(r.get(n.slice(c,i)))}).catch(console.error)}catch(r){throw console.error(r),Error("You must install psl library (https://www.npmjs.com/package/psl) to use `tld` option")}}return n.slice(a,i)}function o(e,t){if(void 0===t&&(t={}),"string"==typeof e)return n(e,t);if(Array.isArray(e)){for(var o=[],i=e.length,s=0;s<i;s++)o.push(n(e[s],t));return o}r()}export{o as default};
var r=["/",":","?","#"],e=[".","/","@"];function t(t,n){for(var i,o=0,f=0,s=0,a=t.length,u=0;a--&&++u&&!(o&&r.indexOf(t[u])>-1);)"."===t[u]&&(++o,f=u);for(i=u,u=f;u--;)if(-1!==e.indexOf(t[u])){s=u+1;break}if(0===s&&i>3)return t;if(s>0&&s<2)return"";if(n.tld){for(var l=0,c=["/","@"],p=f;p--;)if(c.indexOf(t[p])>-1){l=p+1;break}return import("psl").then(function(r){return Promise.resolve(r.get(t.slice(l,i)))}).catch(function(r){throw console.error(r),Error("You must install psl library (https://www.npmjs.com/package/psl) to use `tld` option")})}return t.slice(s,i)}function n(r,e){if(void 0===e&&(e={}),"string"==typeof r)return t(r,e);if(Array.isArray(r)){for(var n=[],i=r.length,o=0;o<i;o++){var f=t(r[o],e);n.push(f)}return n}!function(){throw new TypeError("The given URL is not a string. Please verify your string|array.")}()}export{n as default};
//# sourceMappingURL=extract-domain.module.js.map
{
"name": "extract-domain",
"version": "3.0.1",
"version": "4.1.0",
"description": "Extract domain name from URL",
"type": "module",
"source": "index.js",
"source": "index.ts",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/extract-domain.cjs",

@@ -16,5 +17,5 @@ "default": "./dist/extract-domain.modern.js"

"scripts": {
"build": "npm run pretty && microbundle -i extractDomain -f modern,esm,cjs --external psl index.js",
"build": "npm run pretty && microbundle -i extractDomain -f modern,esm,cjs --external psl index.ts",
"test": "mocha -R spec tests/",
"pretty": "prettier --tab-width=4 --print-width=100 --single-quote --trailing-comma=es5 --write *.js *.js",
"pretty": "prettier --tab-width=4 --print-width=100 --single-quote --trailing-comma=es5 --write *.ts *.ts",
"benchmark": "node benchmark.js"

@@ -21,0 +22,0 @@ },

@@ -9,3 +9,2 @@ # Extract domain name from URL

## Supports

@@ -18,2 +17,3 @@

### Installation
```bash

@@ -24,11 +24,16 @@ $ npm i --save extract-domain

### API
- urls: A string or an array of URLs.
- options { tld: true }: If it should take TLD domains to consideration (i.e. .co.uk)
- returns: A string representing the extracted domain name or an array of domain names.
/\*\*
- @param {Urls} urls ["https://www.google.com", "https://www.github.com"] or "https://www.google.com"
- @param {GetDomainOptions} opts `{ tld: true }` permit to get Top Level Domain like `*.co.uk`
- @returns {Urls | Promise<Urls>} Returns URL(s) or a promise of URL(s) if the PSL lib is being used
\*/
```js
extractDomain(urls, options);
const res = extractDomain(urls, options);
```
ES6 Import
```js

@@ -39,2 +44,3 @@ import extractDomain from 'extract-domain';

CommonJS Require
```js

@@ -45,2 +51,3 @@ const extractDomain = require('extract-domain');

Examples
```js

@@ -66,4 +73,2 @@ const urls = [

To use the code with the PSL support, you have to wrap it in either an async function or use it as a promise.
Examples

@@ -89,3 +94,3 @@

Please note that using the tld flag may significantly slow down the process. Benchmark results:
Please note that using the tld flag may significantly slow down the process. Benchmark (old) results:

@@ -92,0 +97,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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