{"name":"cidr-regex","version":"5.0.1","author":{"name":"silverwind","email":"me@silverwind.io"},"license":"BSD-2-Clause","_id":"cidr-regex@5.0.1","maintainers":[{"name":"silverwind","email":"npm@silverwind.io"}],"contributors":[{"url":"http://flipjs.io/","name":"Felipe Apostol","email":"flipjs.io@gmail.com"}],"homepage":"https://github.com/silverwind/cidr-regex#readme","bugs":{"url":"https://github.com/silverwind/cidr-regex/issues"},"dist":{"shasum":"4b3972457b06445832929f6f268b477fe0372c1f","tarball":"http://registry-npm.ywwl.com/cidr-regex/download/cidr-regex-5.0.1.tgz","fileCount":6,"integrity":"sha512-2Apfc6qH9uwF3QHmlYBA8ExB9VHq+1/Doj9sEMY55TVBcpQ3y/+gmMpcNIBBtfb5k54Vphmta+1IxjMqPlWWAA==","signatures":[{"sig":"MEUCIH0xZI/l8X85uvp6KvpxLux0NLzQG3qONE2gp4Iq+MEpAiEArSGUgQ1t7bGi30THzdxjOyiX4t+piXBS21CfqiVDSQU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6005,"size":2592,"noattachment":false,"key":"/cidr-regex/-/cidr-regex-5.0.1.tgz"},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=20"},"exports":"./dist/index.js","gitHead":"670033a361a71227218a0644aaa4dadff6d3383d","_npmUser":{"name":"silverwind","email":"npm@silverwind.io"},"repository":{"url":"git+https://github.com/silverwind/cidr-regex.git","type":"git"},"_npmVersion":"11.5.1","description":"Regular expression for matching IP addresses in CIDR notation","directories":{},"sideEffects":false,"_nodeVersion":"24.7.0","dependencies":{"ip-regex":"5.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vite":"7.1.7","eslint":"9.36.0","vitest":"3.2.4","updates":"16.7.2","versions":"13.1.2","typescript":"5.9.2","@types/node":"24.5.2","vite-config-silverwind":"6.0.2","eslint-config-silverwind":"105.1.0","vitest-config-silverwind":"10.2.0","typescript-config-silverwind":"10.0.1"},"_npmOperationalInternal":{"tmp":"tmp/cidr-regex_5.0.1_1758647531724_0.2908972470198443","host":"s3://npm-registry-packages-npm-production"},"readme":"# cidr-regex\n[![](https://img.shields.io/npm/v/cidr-regex.svg?style=flat)](https://www.npmjs.org/package/cidr-regex) [![](https://img.shields.io/npm/dm/cidr-regex.svg)](https://www.npmjs.org/package/cidr-regex) [![](https://packagephobia.com/badge?p=cidr-regex)](https://packagephobia.com/result?p=cidr-regex) [![](https://depx.co/api/badge/cidr-regex)](https://depx.co/pkg/cidr-regex)\n\n> Regular expression for matching IP addresses in CIDR notation and bare IP addresses\n\n## Usage\n\n```sh\n$ npm i cidr-regex\n```\n\n```js\nimport cidrRegex from \"cidr-regex\";\n\n// Contains a CIDR IP address?\ncidrRegex().test(\"foo 192.168.0.1/24\");\n//=> true\n\n// Is a CIDR IP address?\ncidrRegex({exact: true}).test(\"foo 192.168.0.1/24\");\n//=> false\n\ncidrRegex.v6({exact: true}).test(\"1:2:3:4:5:6:7:8/64\");\n//=> true\n\n// Extract CIDRs from string\n\"foo 192.168.0.1/24 bar 1:2:3:4:5:6:7:8/64 baz\".match(cidrRegex());\n//=> [\"192.168.0.1/24\", \"1:2:3:4:5:6:7:8/64\"]\n\n// Is a bare IP address?\ncidrRegex({exact: true, prefix: \"none\"}).test(\"192.168.0.1\");\n//=> true\n\n// Is either?\ncidrRegex({exact: true, prefix: \"optional\"}).test(\"192.168.0.1\");\n//=> true\ncidrRegex({exact: true, prefix: \"optional\"}).test(\"192.168.0.1/24\");\n//=> true\n```\n\n## API\n\nAll three functions match CIDR notation by default. The `prefix` option switches them to bare IP addresses or to either.\n\n### cidrRegex(options?: CidrRegexOptions)\n\nReturns a regex for matching both IPv4 and IPv6 CIDR IP addresses.\n\n### cidrRegex.v4(options?: CidrRegexOptions)\n\nReturns a regex for matching IPv4 CIDR IP addresses.\n\n### cidrRegex.v6(options?: CidrRegexOptions)\n\nReturns a regex for matching IPv6 CIDR IP addresses.\n\n#### CidrRegexOptions\n\nThe options object has the following properties:\n\n- `exact` *boolean*: Only match an exact string. Useful with `RegExp#test()` to check if a string is a CIDR IP address. Default: false.\n- `prefix` *string*: Whether a `/prefix` must follow the address. `\"required\"` matches only CIDR, `\"optional\"` matches CIDR and bare IP addresses, `\"none\"` matches only bare IP addresses. Default: `\"required\"`.\n\n## Related\n\n- [ip-bigint](https://github.com/silverwind/ip-bigint) - Convert IPv4 and IPv6 addresses to native BigInt and vice-versa\n- [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses\n- [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation\n- [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address\n- [cidr-tools](https://github.com/silverwind/cidr-tools) - Tools to work with IPv4 and IPv6 CIDR network lists\n\n## License\n\n© [silverwind](https://github.com/silverwind), distributed under BSD licence\n\nBased on previous work by [Felipe Apostol](https://github.com/flipjs)\n","publish_time":1758647531927,"_cnpm_publish_time":1758647531927,"dist-tags":{"latest":"7.1.2"}}