-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
13 changed files
with
57 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ Learn more about [What is a URL](https://developer.mozilla.org/en-US/docs/Learn/ | |
|
||
## Supports | ||
|
||
Both the browser and nodejs. | ||
The browser, Nodejs, and Bun. | ||
|
||
## Usage | ||
|
||
|
@@ -24,21 +24,10 @@ $ npm i --save extract-domain | |
# Install bun https://bun.sh/ | ||
curl -fsSL https://bun.sh/install | bash | ||
# tests | ||
bun test:watch | ||
``` | ||
|
||
### API | ||
|
||
- @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 | ||
const res = extractDomain(urls, options); | ||
``` | ||
|
||
ES6 Import | ||
|
||
```js | ||
|
@@ -54,19 +43,10 @@ const extractDomain = require('extract-domain'); | |
Examples | ||
|
||
```js | ||
const urls = [ | ||
'https://www.npmjs.com/package/extract-domain', | ||
'http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument', | ||
'http://user:[email protected]:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument', | ||
'https://npmjs.com/package/extract-domain', | ||
'ftp://example.org/resource.txt', | ||
'http://example.co.uk/', | ||
'[email protected]', | ||
]; | ||
|
||
extractDomain(urls[0]); // npmjs.com | ||
|
||
extractDomain(urls); // [ 'npmjs.com', 'example.com', 'example.com', 'npmjs.com', 'example.org', 'co.uk', 'email.com' ] | ||
extractDomain('https://www.npmjs.com/package/extract-domain'); // npmjs.com | ||
|
||
// Use the TLD flag, see the section beneath. Returns a promise. | ||
extractDomain(urls, { tld: true }); | ||
``` | ||
|
||
## TLD support | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
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.")}()}; | ||
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")}}; | ||
//# sourceMappingURL=extract-domain.cjs.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.