cidr-regex
Advanced tools
Comparing version
{ | ||
"name": "cidr-regex", | ||
"version": "1.0.7", | ||
"description": "Regular expression for matching CIDR (Classless Inter-Domain Routing)", | ||
"main": "lib/index.js", | ||
"version": "2.0.0", | ||
"description": "Regular expression for matching IP addresses in CIDR notation", | ||
"author": "silverwind <me@silverwind.io>", | ||
"contributors": [ | ||
"Felipe Apostol <flipjs.io@gmail.com> (http://flipjs.io/)" | ||
], | ||
"repository": "silverwind/cidr-regex", | ||
"license": "BSD-2-Clause", | ||
"scripts": { | ||
"commit": "git-cz", | ||
"prebuild": "npm run lint && npm run clean", | ||
"build": "babel --presets es2015 -d lib/ src/", | ||
"clean": "rimraf lib && mkdir lib", | ||
"lint": "eslint src/ test/", | ||
"test": "ava --require babel-register", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
"test": "make test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/flipjs/cidr-regex.git" | ||
}, | ||
"keywords": [ | ||
"cidr", | ||
"regex", | ||
"notation", | ||
"cidr notation", | ||
"prefix", | ||
"prefixes", | ||
"ip", | ||
"ip address", | ||
"cidr", | ||
"netblock", | ||
"regex" | ||
"ip address" | ||
], | ||
"author": "Felipe Apostol <flipjs.io@gmail.com> (http://flipjs.io/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/flipjs/cidr-regex/issues" | ||
}, | ||
"homepage": "https://github.com/flipjs/cidr-regex#readme", | ||
"devDependencies": { | ||
"ava": "0.13.0", | ||
"babel-cli": "6.6.5", | ||
"babel-preset-es2015": "6.6.0", | ||
"babel-register": "6.7.2", | ||
"commitizen": "2.7.3", | ||
"cz-conventional-changelog": "1.1.5", | ||
"eslint": "2.4.0", | ||
"eslint-config-standard": "5.1.0", | ||
"eslint-plugin-babel": "3.1.0", | ||
"eslint-plugin-promise": "1.1.0", | ||
"eslint-plugin-standard": "1.3.2", | ||
"ghooks": "1.0.3", | ||
"rimraf": "2.5.2", | ||
"semantic-release": "4.3.5" | ||
"ava": "^0.24.0", | ||
"eslint": "^4.13.0", | ||
"updates": "^2.0.3" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-conventional-changelog" | ||
}, | ||
"ghooks": { | ||
"pre-commit": "npm run test && npm run build" | ||
} | ||
"dependencies": { | ||
"ip-regex": "^2.1.0" | ||
} | ||
} | ||
} |
# cidr-regex | ||
> Regular expression for matching IP addresses in CIDR notation | ||
Regular expression for matching CIDR (Classless Inter-Domain Routing) | ||
[](https://www.npmjs.org/package/cidr-regex) [](https://www.npmjs.org/package/cidr-regex) [](https://travis-ci.org/silverwind/cidr-regex) | ||
[](https://github.com/semantic-release/semantic-release) | ||
[](http://npm.im/cidr-regex) | ||
[](http://opensource.org/licenses/MIT) | ||
[](https://travis-ci.org/flipjs/cidr-regex) | ||
[](https://github.com/feross/standard) | ||
[](http://commitizen.github.io/cz-cli/) | ||
[](http://npm-stat.com/charts.html?package=cidr-regex&from=2016-03-24) | ||
## Install | ||
@@ -22,19 +15,17 @@ | ||
```js | ||
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 | ||
const cidrRegex = require('cidr-regex'); | ||
// is a CIDR v4 | ||
cidr.test('18.101.25.153/24') // true | ||
// Contains a CIDR IP address? | ||
cidrRegex().test('foo 192.168.0.1/24'); | ||
//=> true | ||
// is not a CIDR v4 | ||
cidrv4.test('999.999.999.999/12') // false | ||
// Is a CIDR IP address? | ||
cidrRegex({exact: true}).test('foo 192.168.0.1/24'); | ||
//=> false | ||
// is a CIDR v6 | ||
cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156') // true | ||
cidrRegex.v6({exact: true}).test('1:2:3:4:5:6:7:8/64'); | ||
//=> true | ||
// is not a CIDR v6 | ||
cidrv6.test('fe80:0000:0000:0000:0204:61ff:fe9d:f156/a') // false | ||
'foo 192.168.0.1/24 bar 1:2:3:4:5:6:7:8/64 baz'.match(cidrRegex()); | ||
//=> ['192.168.0.1', '1:2:3:4:5:6:7:8'] | ||
``` | ||
@@ -44,21 +35,32 @@ | ||
### cidr | ||
### cidrRegex([options]) | ||
A regex for matching CIDR IPv4 | ||
Returns a regex for matching both IPv4 and IPv6 CIDR IP addresses. | ||
### cidrv4 | ||
### cidrRegex.v4([options]) | ||
A regex for matching CIDR IPv4 | ||
Returns a regex for matching IPv4 CIDR IP addresses. | ||
### cidrv6 | ||
### cidrRegex.v6([options]) | ||
A regex for matching CIDR IPv6 | ||
Returns a regex for matching IPv6 CIDR IP addresses. | ||
## Other notes | ||
#### options.exact | ||
This was inspired by npm package [ip-regex](https://www.npmjs.com/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](https://www.helpsystems.com/intermapper/ipv6-test-address-validation) (licensed under CC-BY-SA 3.0). | ||
Type: `boolean`<br> | ||
Default: `false` *(Matches any CIDR IP address in a string)* | ||
Only match an exact string. Useful with `RegExp#test()` to check if a string is a CIDR IP address. | ||
## Related | ||
- [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is a CIDR IP address | ||
- [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP prefex | ||
- [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses | ||
## License | ||
MIT © [Felipe Apostol](https://github.com/flipjs) | ||
© [silverwind](https://github.com/silverwind), distributed under BSD licence | ||
Based on previous work by [Felipe Apostol](https://github.com/flipjs) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
181347
727.88%3
-78.57%11
37.5%65
3.17%1
Infinity%406
-30.95%1
Infinity%1
Infinity%2
100%2
100%+ Added
+ Added