Norse Polytheistic Mythology
    Have ideas to improve npm?Join in the discussion! »

    is-domain-valid

    1.2.0 • Public • Published

    Is Domain Valid

    Dependency free domain name syntax validator with TLD checking and IDN support. See below examples to check what the validator checks for:

    Valid examples

    example.com
    sub.example.com // allowSubdomain options is requried
    exa-mple.com
    xn--c1yn36f.com // allowIdn option is required
    *.wildcard.com // allowWildcard and allowSubdomain options are required

    Invalid examples

    123
    123.123 // checkTld option is required
    example
    exam_ple.com
    -example.com
    example-.com
    exa--mple.com
    example.doesnotexist // checkTld option is required
    xn--c1yn--bb.com
    *.com
    example.*.com

    Installation

    Install the library with npm --save is-domain-valid

    Usage

    const isDomainValid = require('../is-domain-valid');
    const res = isDomainValid('example.com');
    if (res.result) {
      console.log('Domain is valid');
    } else {
      console.error(`Domain is not valid because of: ${res.message}`);
    }

    Options

    Options can be passed as a second argument in isDomainValid function:

    const defaultOptions = {
      checkTld: true,
      allowIdn: true,
      allowSubdomain: true,
      allowWildcard: false
    };
    const res = isDomainValid('example.com', defaultOptions);

    Build and contribution

    Push requests are very welcome. Run tests with npm run tests and then build the library with npm run build.

    Author

    Adam Blok: https://github.com/adamblok

    License

    MIT

    Install

    npm i is-domain-valid

    DownloadsWeekly Downloads

    4

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    40.8 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar