https://github.com/linusu/is-my-ip-valid
A small lib to validate IP addresses
https://github.com/linusu/is-my-ip-valid
Last synced: about 1 year ago
JSON representation
A small lib to validate IP addresses
- Host: GitHub
- URL: https://github.com/linusu/is-my-ip-valid
- Owner: LinusU
- License: mit
- Created: 2018-02-14T13:16:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-01T16:21:50.000Z (over 4 years ago)
- Last Synced: 2025-05-06T21:02:28.096Z (about 1 year ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Is my IP valid
A small lib to validate IP addresses.
## Installation
```sh
npm install --save is-my-ip-valid
```
## Usage
```js
const validator = require('is-my-ip-valid')
const validate = validator()
const validate4 = validator({ version: 4 })
const validate6 = validator({ version: 6 })
console.log(validate('127.0.0.1'))
//=> true
console.log(validate4('127.0.0.1'))
//=> true
console.log(validate6('127.0.0.1'))
//=> false
console.log(validate('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
//=> true
console.log(validate4('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
//=> false
console.log(validate6('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
//=> true
```
## Acknowledgements
The code is mostly based on this wonderful library: [beaugunderson/ip-address](https://github.com/beaugunderson/ip-address)
All regexes used are audited for catastrophic backtracking by this module: [substack/safe-regex](https://github.com/substack/safe-regex)