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 4.1.4 to 4.1.5

bun.lockb

12

package.json
{
"name": "extract-domain",
"version": "4.1.4",
"version": "4.1.5",
"description": "Extract domain name from URL",

@@ -17,6 +17,7 @@ "type": "module",

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

@@ -48,3 +49,4 @@ "repository": {

"nanobench": "^1.0.3",
"prettier": "^1.11.1"
"prettier": "^1.11.1",
"psl": "^1.9.0"
},

@@ -51,0 +53,0 @@ "peerDependencies": {

@@ -21,2 +21,13 @@ # Extract domain name from URL

### Development
```
# Install bun https://bun.sh/
curl -fsSL https://bun.sh/install | bash
# tests
bun test:watch
```
### API

@@ -98,3 +109,3 @@

```bash
$ npm test
$ bun test
```

@@ -105,3 +116,3 @@

```bash
$ npm run pretty
$ bun pretty
```

@@ -112,3 +123,3 @@

```bash
$ npm run benchmark
$ bun benchmark
```

@@ -115,0 +126,0 @@

import assert from 'assert';
import extractDomain from '../dist/extract-domain.modern.js';
import { test } from 'bun:test';
import extractDomain from '../index.ts';
// import extractDomain from '../dist/extract-domain.modern.js';

@@ -30,110 +32,105 @@ const urls = [

describe('extract domain', () => {
it('should return the domain if it already has been extracted', () => {
assert.strictEqual(extractDomain('example.com'), 'example.com');
});
test('should return the domain if it already has been extracted', () => {
assert.strictEqual(extractDomain('example.com'), 'example.com');
});
it('should extract given domain from url', () => {
assert.strictEqual(extractDomain(urls[0]), expected[0]);
assert.strictEqual(extractDomain(urls[1]), expected[1]);
assert.strictEqual(extractDomain(urls[7]), expected[0]);
assert.strictEqual(extractDomain(urls[8]), expected[0]);
assert.strictEqual(extractDomain(urls[10]), expected[4]);
assert.strictEqual(extractDomain(urls[12]), expected[6]);
});
test('should extract given domain from url', () => {
assert.strictEqual(extractDomain(urls[0]), expected[0]);
assert.strictEqual(extractDomain(urls[1]), expected[1]);
assert.strictEqual(extractDomain(urls[7]), expected[0]);
assert.strictEqual(extractDomain(urls[8]), expected[0]);
assert.strictEqual(extractDomain(urls[10]), expected[4]);
assert.strictEqual(extractDomain(urls[12]), expected[6]);
});
it('should extract given domain from an array of urls', () => {
const domains = extractDomain(urls);
test('should extract given domain from an array of urls', () => {
const domains = extractDomain(urls);
domains.map((domain) => assert(expected.indexOf(domain) > -1));
});
domains.map((domain) => assert(expected.indexOf(domain) > -1));
});
it('should return empty string if it is not a url', () => {
assert.strictEqual(extractDomain('/i.am/just.astring//7test'), '');
});
test('should return empty string if it is not a url', () => {
assert.strictEqual(extractDomain('/i.am/just.astring//7test'), '');
});
it('should throw syntax error exception if the argument is not string nor array', () => {
try {
extractDomain({});
} catch (e) {
assert.strictEqual(e.name, 'TypeError');
test('should throw syntax error exception if the argument is not string nor array', () => {
try {
extractDomain({});
} catch (e) {
assert.strictEqual(e.name, 'TypeError');
assert.strictEqual(
e.message,
'The given URL is not a string. Please verify your string|array.'
);
}
});
it('should throw syntax error exception if the array value is not a string', () => {
try {
extractDomain([['wow']]);
} catch (e) {
assert.strictEqual(e.name, 'TypeError');
assert.strictEqual(
e.message,
'The given URL is not a string. Please verify your string|array.'
);
}
});
it('should support tld if options flag is used', async () => {
assert.strictEqual(
await extractDomain(
'http://www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: true }
),
'example.co.uk'
e.message,
'The given URL is not a string. Please verify your string|array.'
);
}
});
assert.strictEqual(
await extractDomain(
'http://user:password@www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: true }
),
'example.co.uk'
);
test('should throw syntax error exception if the array value is not a string', () => {
try {
extractDomain([['wow']]);
} catch (e) {
assert.strictEqual(e.name, 'TypeError');
assert.strictEqual(
await extractDomain(
'http://user:password@www.so.many.sub.domains.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: true }
),
'example.com'
e.message,
'The given URL is not a string. Please verify your string|array.'
);
}
});
assert.strictEqual(
await extractDomain('https://example.com', { tld: true }),
'example.com'
);
});
test('should support tld if options flag is used', async () => {
assert.strictEqual(
await extractDomain(
'http://www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: true }
),
'example.co.uk'
);
it('should not support tld if options flag is used with false value', () => {
assert.strictEqual(
extractDomain(
'http://www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: false }
),
'co.uk'
);
assert.strictEqual(
await extractDomain(
'http://user:password@www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: true }
),
'example.co.uk'
);
assert.strictEqual(
extractDomain(
'http://user:password@www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: false }
),
'co.uk'
);
assert.strictEqual(
await extractDomain(
'http://user:password@www.so.many.sub.domains.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: true }
),
'example.com'
);
assert.strictEqual(
extractDomain(
'http://user:password@www.so.many.sub.domains.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: false }
),
'example.com'
);
assert.strictEqual(await extractDomain('https://example.com', { tld: true }), 'example.com');
});
assert.strictEqual(extractDomain('https://example.com', { tld: false }), 'example.com');
});
test('should not support tld if options flag is used with false value', () => {
assert.strictEqual(
extractDomain(
'http://www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: false }
),
'co.uk'
);
assert.strictEqual(
extractDomain(
'http://user:password@www.so.many.sub.domains.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: false }
),
'co.uk'
);
assert.strictEqual(
extractDomain(
'http://user:password@www.so.many.sub.domains.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument',
{ tld: false }
),
'example.com'
);
assert.strictEqual(extractDomain('https://example.com', { tld: false }), 'example.com');
});

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