Skip to content

Commit d4a6160

Browse files
committed
BREAKING CHANGE: Remove the possibility to add an array of URLs
This will make the API more clean. We still have the issue with TLDs and the return of a promise, but no way around that one.
1 parent cd529e4 commit d4a6160

13 files changed

+57
-84
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Learn more about [What is a URL](https://developer.mozilla.org/en-US/docs/Learn/
88

99
## Supports
1010

11-
Both the browser and nodejs.
11+
The browser, Nodejs, and Bun.
1212

1313
## Usage
1414

@@ -24,21 +24,10 @@ $ npm i --save extract-domain
2424
# Install bun https://bun.sh/
2525
curl -fsSL https://bun.sh/install | bash
2626
27-
2827
# tests
2928
bun test:watch
3029
```
3130

32-
### API
33-
34-
- @param {Urls} urls ["https://www.google.com", "https://www.github.com"] or "https://www.google.com"
35-
- @param {GetDomainOptions} opts `{ tld: true }` permit to get Top Level Domain like `*.co.uk`
36-
- @returns {Urls | Promise<Urls>} Returns URL(s) or a promise of URL(s) if the PSL lib is being used
37-
38-
```js
39-
const res = extractDomain(urls, options);
40-
```
41-
4231
ES6 Import
4332

4433
```js
@@ -54,19 +43,10 @@ const extractDomain = require('extract-domain');
5443
Examples
5544

5645
```js
57-
const urls = [
58-
'https://www.npmjs.com/package/extract-domain',
59-
'http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
60-
'http://user:[email protected]:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
61-
'https://npmjs.com/package/extract-domain',
62-
'ftp://example.org/resource.txt',
63-
'http://example.co.uk/',
64-
65-
];
66-
67-
extractDomain(urls[0]); // npmjs.com
68-
69-
extractDomain(urls); // [ 'npmjs.com', 'example.com', 'example.com', 'npmjs.com', 'example.org', 'co.uk', 'email.com' ]
46+
extractDomain('https://www.npmjs.com/package/extract-domain'); // npmjs.com
47+
48+
// Use the TLD flag, see the section beneath. Returns a promise.
49+
extractDomain(urls, { tld: true });
7050
```
7151

7252
## TLD support

dist/extract-domain.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
function r(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,e}var e=["/",":","?","#"],t=[".","/","@"];function n(n,o){for(var i,u=0,f=0,s=0,a=n.length,c=0;a--&&++c&&!(u&&e.indexOf(n[c])>-1);)"."===n[c]&&(++u,f=c);for(i=c,c=f;c--;)if(-1!==t.indexOf(n[c])){s=c+1;break}if(0===s&&i>3)return n;if(s>0&&s<2)return"";if(o.tld){for(var l=0,p=["/","@"],v=f;v--;)if(p.indexOf(n[v])>-1){l=v+1;break}return Promise.resolve().then(function(){/*#__PURE__*/return r(require("psl"))}).then(function(r){return Promise.resolve(r.get(n.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 n.slice(s,i)}module.exports=function(r,e){if(void 0===e&&(e={}),"string"==typeof r)return n(r,e);if(Array.isArray(r)){for(var t=[],o=r.length,i=0;i<o;i++){var u=n(r[i],e);t.push(u)}return t}!function(){throw new TypeError("The given URL is not a string. Please verify your string|array.")}()};
1+
function e(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var r=["/",":","?","#"],t=[".","/","@"];module.exports=function(o,n){void 0===n&&(n={});try{if("string"==typeof o)return function(o,n){for(var i,s=0,a=0,c=0,l=o.length,u=0;l--&&++u&&!(s&&r.indexOf(o[u])>-1);)"."===o[u]&&(++s,a=u);for(i=u,u=a;u--;)if(-1!==t.indexOf(o[u])){c=u+1;break}if(0===c&&i>3)return o;if(c>0&&c<2)return"";if(n.tld){for(var f=0,p=["/","@"],d=a;d--;)if(p.indexOf(o[d])>-1){f=d+1;break}return Promise.resolve().then(function(){/*#__PURE__*/return e(require("psl"))}).then(function(e){return Promise.resolve(e.get(o.slice(f,i)))}).catch(function(e){throw console.error(e),Error("You must install psl library (https://www.npmjs.com/package/psl) to use `tld` option")})}return o.slice(c,i)}(o,n);if(Array.isArray(o))return console.error("Sorry, it is no longer possible to pass an array of URLs. Please use a string instead.","I.e. extractDomain('https://www.google.com')."),o}catch(e){throw console.error(e),new TypeError("The given string is not a valid URL. https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL")}};
22
//# sourceMappingURL=extract-domain.cjs.map

dist/extract-domain.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/extract-domain.modern.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)