Performant domain name extraction. No regex or array magic.
However. This package will also remove the sub domain.
Browser and Node.
$ npm i --save extract-domain
- urls = string|array
- returns string|array
extractDomain(urls);
ES6
import extractDomain from 'extract-domain';
const extractDomain = require('extract-domain');
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:password@example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
'https://npmjs.com/package/extract-domain',
'ftp://example.org/resource.txt',
'this.is.my@email.com'
];
extractDomain(urls[0]); // npmjs.com
extractDomain(urls); // [ 'npmjs.com', 'example.com', 'example.com', 'npmjs.com', 'example.org', 'email.com' ]
$ npm test
$ npm run pretty
$ npm run benchmark
Contributions are appreciated.
MIT-licensed. See LICENSE.
If this project has been helpful in any way, and you want to treat me a cup of coffee, please donate :)