Skip to content

Commit

Permalink
Add tld support behind options flag (#7)
Browse files Browse the repository at this point in the history
The options flag is { tld: true }. This PR will also create a more modern solution to packaging by using microbundle
  • Loading branch information
bjarneo authored Apr 28, 2021
1 parent eafbb9b commit 5d29e02
Show file tree
Hide file tree
Showing 15 changed files with 15,459 additions and 4,745 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ extractDomain(urls); // [ 'npmjs.com', 'example.com', 'example.com', 'npmjs.com'

```

TLD support
--
```js
const url = 'http://www.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument';

extractDomain(url, { tld: true });
// example.co.uk
```
However, using the tld flag will slow down the process by many seconds. Benchmark:
```
# extract domain 10,000 times
end ~14 ms (0 s + 13572914 ns)
# extract domain with tld 10,000 times
end ~4.29 s (4 s + 288108681 ns)
```

Tests
--
```bash
Expand Down
14 changes: 12 additions & 2 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const bench = require('nanobench');
const extractDomainDist = require('./dist/extract-domain.min');
const extractDomainDist = require('./dist/extract-domain');
const extractDomain = require('./index');
const url = 'https://www.npmjs.com/package/extract-domain';

const times = 2500000;
const times = 10000;

const timesToLocale = times.toLocaleString();

Expand Down Expand Up @@ -45,6 +45,16 @@ bench(`extract domain ${timesToLocale} times`, b => {
b.end();
});

bench(`extract domain with tld ${timesToLocale} times`, b => {
b.start();

for (let i = 0; i < times; i++) {
extractDomain(url, { tld: true }) === 'npmjs.com';
}

b.end();
});

bench(`extract domain regex ${timesToLocale} times`, b => {
b.start();

Expand Down
2 changes: 2 additions & 0 deletions dist/extract-domain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/extract-domain.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions dist/extract-domain.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions dist/extract-domain.modern.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/extract-domain.modern.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/extract-domain.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/extract-domain.module.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/extract-domain.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/extract-domain.umd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5d29e02

Please sign in to comment.