GithubHelp home page GithubHelp logo

miguelmota / is-valid-hostname Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 5.0 17 KB

Validate hostname in JavaScript based on RFC-1123

Home Page: https://github.com/miguelmota/is-valid-hostname

License: MIT License

HTML 13.79% JavaScript 86.21%
javascript nodejs validation hostname domain

is-valid-hostname's Introduction

is-valid-hostname

Validate hostname in JavaScript based on RFC-1123.

Demo

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

Install

npm install is-valid-hostname

Usage

const isValidHostname = require('is-valid-hostname')

isValidHostname('localhost') // true
isValidHostname('example.com') // true
isValidHostname('foo.example.com') // true
isValidHostname('bar.foo.example.com') // true
isValidHostname('exa-mple.co.uk') // true
isValidHostname('xn--80ak6aa92e.com') // true
isValidHostname('9gag.com') // true
isValidHostname('8.8.8.8') // true
isValidHostname('127.0.0.1') // true
isValidHostname('exa_mple.com') // false
isValidHostname('-example.com') // false
isValidHostname('example.com:3000') // false
isValidHostname('8.8.8.8:3000') // false

View more examples.

Test

npm test

FAQ

  • Q: Why are numbers allowed in top-level domain?

    • A: Numbers in TLD are allowed under RFC-1123. See this answer for more information.

License

MIT

is-valid-hostname's People

Contributors

miguelmota avatar richienb avatar ryheath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

is-valid-hostname's Issues

`package.json` is missing a reference to the TypeScript typings

Currently, the TypeScript compiler can't find the typings included with this library without users manually referencing them (see #5).

To allow the compiler to find these typings and associate them with the main module, we just need to add

"types": "types/index.d.ts",

to package.json. ๐Ÿ™‚

How to import types?

Hi @miguelmota!

First of all thank you for this amazing package. I ran up against an issue of importing the package into a typescript project.
The compiler tells the following

Could not find a declaration file for module 'is-valid-hostname'. '/home/daniel/danielproject/node_modules/is-valid-hostname/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/is-valid-hostname` if it exists or add a new declaration (.d.ts) file containing `declare module 'is-valid-hostname';

I've tried to add your types both in compilerOptions.typeRoots and compilerOptions.paths like that

"compilerOptions": {
  "typeRoots": [
    "node_modules/@types",
    "node_modules/is-valid-hostname/types/*"
  ],
}
"compilerOptions": {
  "paths": {
    "*": [
      "node_modules/*",
      "node_modules/is-valid-hostname/types/*"
    ]
  },
}

I will be very grateful if you can help me

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.