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

is-valid-host

1.0.0 • Public • Published

is-valid-host

Validates if string is a valid host based on RFC-7230.

Demo

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

Install

npm install is-valid-host

Usage

const isValidHost = require('is-valid-host')

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

View more examples.

Test

npm test

License

MIT

Install

npm i is-valid-host

DownloadsWeekly Downloads

294

Version

1.0.0

License

MIT

Unpacked Size

12.4 kB

Total Files

11

Last publish

Collaborators

  • avatar