Installations
npm install extract-domain
Score
99.6
Supply Chain
100
Quality
78.7
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
No
Node Version
20.10.0
NPM Version
10.2.3
Statistics
31 Stars
101 Commits
4 Forks
4 Watching
3 Branches
3 Contributors
Updated on 02 Nov 2024
Bundle Size
1.08 kB
Minified
664.00 B
Minified + Gzipped
Languages
JavaScript (63.52%)
TypeScript (36.48%)
Total Downloads
Cumulative downloads
Total Downloads
5,537,629
Last day
8.5%
11,610
Compared to previous day
Last week
12.3%
54,946
Compared to previous week
Last month
18.9%
223,005
Compared to previous month
Last year
48.5%
2,292,277
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
6
Extract domain name from URL
This package provides a performant way to extract domain names from URLs without using regular expressions or array manipulations.
Learn more about What is a URL
Supports
- ESM
- Node.js
- Browser
Usage
Installation
1$ npm i --save extract-domain
Development
# 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
} Returns URL(s) or a promise of URL(s) if the PSL lib is being used
ESM import
1import extractDomain from 'extract-domain';
Examples
1const urls = [ 2 'https://www.npmjs.com/package/extract-domain', 3 'http://www.example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument', 4 'http://user:password@example.com:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument', 5 'https://npmjs.com/package/extract-domain', 6 'ftp://example.org/resource.txt', 7 'http://example.co.uk/', 8 'this.is.my@email.com', 9]; 10 11extractDomain(urls[0]); // npmjs.com 12 13extractDomain(urls); // [ 'npmjs.com', 'example.com', 'example.com', 'npmjs.com', 'example.org', 'co.uk', 'email.com' ]
TLD support
TLD support requires the optional dependency of the psl
library.
Examples
1npm i --save-optional psl
1const url = 2 'http://www.example.co.uk:80/path/to/myfile.html?key1=value1&key2=value2#SomewhereInTheDocument'; 3 4async function extract(url) { 5 console.log(await extractDomain(url, { tld: true })); 6 // example.co.uk 7} 8 9// Or 10extractDomain(url, { tld: true }).then(console.log); 11// example.co.uk
Please note that using the tld flag may significantly slow down the process. Benchmark (old) results:
# 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
1$ bun test
Coding style
1$ bun pretty
Benchmark
1$Â bun benchmark
Contribution
Contributions are appreciated.
License
MIT-licensed. See LICENSE.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/bjarneo/extract-domain/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/bjarneo/extract-domain/ci.yml/master?enable=pin
- Info: 0 out of 1 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Reason
11 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Score
2.8
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More