Socket
Socket
Sign inDemoInstall

is-valid-domain

Package Overview
Dependencies
1
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    is-valid-domain

Validate domain name


Version published
Weekly downloads
448K
decreased by-3.27%
Maintainers
1
Install size
144 kB
Created
Weekly downloads
 

Readme

Source

is-valid-domain

Validate domain name in JavaScript

Demo

https://lab.miguelmota.com/is-valid-domain

Install

npm install is-valid-domain

Usage

const isValidDomain = require('is-valid-domain')

isValidDomain('example.com') // true
isValidDomain('foo.example.com') // true
isValidDomain('bar.foo.example.com') // true
isValidDomain('exa-mple.co.uk') // true
isValidDomain('xn--80ak6aa92e.com') // true
isValidDomain('_dnslink.ipfs.io') // true
isValidDomain('exa_mple.com') // false
isValidDomain('-example.co.uk') // false
isValidDomain('example') // false
isValidDomain('ex*mple.com') // false
isValidDomain('*.example.com') // false
isValidDomain('*.com') // false
isValidDomain(3434) // false

isValidDomain('foo.example.com', {subdomain: true}) // true
isValidDomain('foo.example.com', {subdomain: false}) // false
isValidDomain('*.example.com', {wildcard: false}) // false
isValidDomain('*.example.com', {wildcard: true}) // true
isValidDomain('*.example.com', {subdomain: false, wildcard: true}) // false
isValidDomain('はじめよう.みんな') // false
isValidDomain('はじめよう.みんな', {allowUnicode: true}) // true
isValidDomain('ai.') // false
isValidDomain('ai.', {topLevel: true}) // true

view more examples

Test

npm test

Contributing

Adding new domains:

  • Add second level domain to data/second_level_domains.csv
  • Run npm run generate to generate JSON map file
  • Run npm test

FAQ

  • Q: Why is trailing dot . in domain names verified as true?

    • A: Fully qualified domain names allow the trailing dot which represents the root zone. More info here and here.

License

MIT

Keywords

FAQs

Last updated on 22 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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