2021-08-27 08:30:39 +02:00
..
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00
2021-08-27 08:30:39 +02:00

cidr-regex

Regular expression for matching CIDR (Classless Inter-Domain Routing)

semantic-release
version
MIT License
travis build
js-standard-style
Commitizen friendly
downloads

Install

$ npm install --save cidr-regex

Usage

import cidr from 'cidr-regex' // default regex is cidr v4
import { cidrv4, cidrv6 } from 'cidr-regex'
// OR
var cidrv4 = require('cidr-regex').cidrv4
var cidrv6 = require('cidr-regex').cidrv6

// is a CIDR v4
cidr.test('18.101.25.153/24') // true

// is not a CIDR v4
cidrv4.test('999.999.999.999/12') // false

// is a CIDR v6
cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156') // true

// is not a CIDR v6
cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156/a') // false

API

cidr

A regex for matching CIDR IPv4

cidrv4

A regex for matching CIDR IPv4

cidrv6

A regex for matching CIDR IPv6

Other notes

This was inspired by npm package ip-regex. I've used the same samples on unit testing for IPv4 and modified for CIDR testing. Other IPv6 test cases were taken from IPv6 Regex by Dartware, LLC (licensed under CC-BY-SA 3.0).

License

MIT © Felipe Apostol