What is is-cidr?
The is-cidr npm package is a utility for validating and parsing CIDR (Classless Inter-Domain Routing) notations. It helps in determining whether a given string is a valid CIDR notation for IPv4 or IPv6 addresses.
What are is-cidr's main functionalities?
Validate IPv4 CIDR
This feature allows you to check if a given string is a valid IPv4 CIDR notation. The function returns true if the input is a valid IPv4 CIDR and false otherwise.
const isCidr = require('is-cidr');
console.log(isCidr.v4('192.168.0.1/24')); // true
console.log(isCidr.v4('192.168.0.1')); // false
Validate IPv6 CIDR
This feature allows you to check if a given string is a valid IPv6 CIDR notation. The function returns true if the input is a valid IPv6 CIDR and false otherwise.
const isCidr = require('is-cidr');
console.log(isCidr.v6('2001:db8::/32')); // true
console.log(isCidr.v6('2001:db8::')); // false
Validate both IPv4 and IPv6 CIDR
This feature allows you to check if a given string is a valid CIDR notation for either IPv4 or IPv6. The function returns 4 for valid IPv4 CIDR, 6 for valid IPv6 CIDR, and 0 for invalid CIDR.
const isCidr = require('is-cidr');
console.log(isCidr('192.168.0.1/24')); // 4
console.log(isCidr('2001:db8::/32')); // 6
console.log(isCidr('invalid-cidr')); // 0
Other packages similar to is-cidr
cidr-regex
The cidr-regex package provides regular expressions for matching CIDR notations. It can be used to validate and extract CIDR notations from strings. Unlike is-cidr, it focuses on pattern matching using regular expressions.
ip-cidr
The ip-cidr package offers more comprehensive CIDR manipulation capabilities, including validation, parsing, and conversion between CIDR and IP ranges. It provides a broader set of functionalities compared to is-cidr, which is primarily focused on validation.
netmask
The netmask package is used for IP address and network mask manipulation. It allows for CIDR validation, subnet calculations, and IP range generation. It offers more advanced network-related functionalities compared to the simpler validation focus of is-cidr.
is-cidr
Check if a string is an IP address in CIDR notation
Install
$ npm install --save is-cidr
Usage
const isCidr = require('is-cidr');
isCidr('192.168.0.1/24');
isCidr('1:2:3:4:5:6:7:8/64');
isCidr.v4('1:2:3:4:5:6:7:8/64');
API
isCidr(input)
Check if input
is a IPv4 or IPv6 CIDR address.
isCidr.v4(input)
Check if input
is IPv4 CIDR address.
isCidr.v6(input)
Check if input
is IPv6 CIDR address.
Related
- cidr-regex - Regular expression for matching IP addresses in CIDR notation
- is-ip - Check if a string is an IP address
- ip-regex - Regular expression for matching IP addresses
License
© silverwind, distributed under BSD licence
Based on previous work by Felipe Apostol