1.0.0 • Published 1 year ago

valid-ip v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

valid-ip

npm npm bundle size NPM npm

Provides a small and reliable IPv4 and IPv6 validation library.

Installation

npm i valid-ip

Documentation

Example

const { isV4, isV6 } = require('valid-ip')

isV4('175.21.195.5') // true

isV6('5b93:c18f:27e6:f322:530a:1a5d:74c8:e2c2') // true

How it works

The functions receives a string parameter and process the value to validate if it matches the following rules:

An IPv4 address has the format: x . x . x . x where x is called an octet and must be a decimal value between 0 and 255.

  • No leading 0
  • In range of (0 - 255)
  • Has exactly 4 cells
  • Has an integer in each cell

An IPv6 address has the format x : x : x : x : x : x : x : x, where x is called a segment and can be any hexadecimal value between 0 and FFFF.

  • Can be composed to just one 0
  • In hexadecimal range of (0000 - FFFF)
  • Has exactly 8 cells
  • No cells are empty

References

License

MIT License