{"name":"cidr-tools","version":"11.2.0","author":{"name":"silverwind","email":"me@silverwind.io"},"license":"BSD-2-Clause","_id":"cidr-tools@11.2.0","maintainers":[{"name":"silverwind","email":"npm@silverwind.io"}],"homepage":"https://github.com/silverwind/cidr-tools#readme","bugs":{"url":"https://github.com/silverwind/cidr-tools/issues"},"dist":{"shasum":"5ffde6736e300b3ad5e5b06114be15812f05ca71","tarball":"http://registry-npm.ywwl.com/cidr-tools/download/cidr-tools-11.2.0.tgz","fileCount":5,"integrity":"sha512-WJM2u3wfOhzGR3SQiXS1n+Y1/a7ONSZ19HP4n/5a0+xaxKyy/nRngDZfxw/zCXp04VVBHpdD6JryoR1Tv+LOcg==","signatures":[{"sig":"MEYCIQCSU8kaBL1N6k103wAmN0KrmL6uPgh1qEbn+aU3oVaBdQIhAOvieCQng+vFvJWCBte8my1gQX1vez0alq7oARIOhZmY","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/cidr-tools@11.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":25032,"size":6743,"noattachment":false,"key":"/cidr-tools/-/cidr-tools-11.2.0.tgz"},"main":"./dist/index.js","type":"module","_from":"file:cidr-tools-11.2.0.tgz","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":"./dist/index.js","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:061a4d47-ba6b-4c24-838a-fc88de75c8e0"}},"_resolved":"/tmp/af6a513457b0c841bc1494be3fa95adc/cidr-tools-11.2.0.tgz","_integrity":"sha512-WJM2u3wfOhzGR3SQiXS1n+Y1/a7ONSZ19HP4n/5a0+xaxKyy/nRngDZfxw/zCXp04VVBHpdD6JryoR1Tv+LOcg==","repository":{"url":"git+https://github.com/silverwind/cidr-tools.git","type":"git"},"_npmVersion":"11.11.0","description":"Tools to work with IPv4 and IPv6 CIDR","directories":{},"sideEffects":false,"_nodeVersion":"25.8.0","dependencies":{"ip-bigint":"^8.2.9"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"9.39.3","tsdown":"0.21.0","vitest":"4.0.18","updates":"17.8.1","versions":"14.2.1","typescript":"5.9.3","@types/node":"25.3.3","jest-extended":"7.0.0","eslint-config-silverwind":"121.2.0","tsdown-config-silverwind":"2.0.0","vitest-config-silverwind":"10.6.3","updates-config-silverwind":"1.0.3","@typescript/native-preview":"7.0.0-dev.20260305.1","typescript-config-silverwind":"15.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cidr-tools_11.2.0_1772747954854_0.4707740026043532","host":"s3://npm-registry-packages-npm-production"},"readme":"# cidr-tools\n[![](https://img.shields.io/npm/v/cidr-tools.svg?style=flat)](https://www.npmjs.org/package/cidr-tools) [![](https://img.shields.io/npm/dm/cidr-tools.svg)](https://www.npmjs.org/package/cidr-tools) [![](https://img.shields.io/bundlephobia/minzip/cidr-tools.svg)](https://bundlephobia.com/package/cidr-tools) [![](https://packagephobia.com/badge?p=cidr-tools)](https://packagephobia.com/result?p=cidr-tools) [![](https://depx.co/api/badge/cidr-tools)](https://depx.co/pkg/cidr-tools)\n\n> Tools to work with IPv4 and IPv6 CIDR\n\n## Usage\n\n```sh\npnpm add cidr-tools\n```\n\n```js\nimport {mergeCidr, excludeCidr, expandCidr, overlapCidr, containsCidr, normalizeCidr, parseCidr} from \"cidr-tools\";\n\nmergeCidr([\"1.0.0.0/24\", \"1.0.1.0/24\"]);\n//=> [\"1.0.0.0/23\"]\n\nexcludeCidr([\"::1/127\"], \"::1/128\");\n//=> [\"::/128\"]\n\nArray.from(expandCidr([\"2001:db8::/126\"]));\n//=> [\"2001:db8::\", \"2001:db8::1\", \"2001:db8::2\", \"2001:db8::3\"]\n\noverlapCidr(\"1.0.0.0/24\", \"1.0.0.128/25\");\n//=> true\n\ncontainsCidr([\"1.0.0.0/24\", \"2.0.0.0/24\"], \"1.0.0.1\");\n//=> true\n\nnormalizeCidr(\"::ffff/64\");\n//=> \"::/64\"\n\nparseCidr(\"::/64\");\n//=> {cidr: \"::/64\", ip: \"::\", version: 6, prefix: \"64\", prefixPresent: true, start: 0n, end: 18446744073709551615n}\n```\n\n## API\n\nAll functions take CIDR addresses or single IP addresses. On single addresses, a prefix of `/32` or `/128` is assumed. `mergeCidr`, `excludeCidr` and `expandCidr` return a merged and sorted set with IPv4 sorted before IPv6.\n\nNetworks are validated with [cidr-regex](https://github.com/silverwind/cidr-regex) and anything that is not a CIDR or IP address throws, including out-of-family prefixes like `1.2.3.4/33` and ambiguous zero-padded octets like `010.0.0.1`.\n\nEvery function takes a trailing `[opts]` *Object*:\n  - `validate`: Whether to reject networks that are not a CIDR or IP address. `false` skips the check for input already known to be valid, and then malformed input is parsed on a best-effort basis. Default: `true`.\n\nThis module requires [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#browser_compatibility) support in your environment.\n\n### mergeCidr(networks, [opts])\n\n- `networks` *String* or *Array*: One or more CIDR or IP addresses.\n\nReturns an array of merged networks.\n\n### excludeCidr(baseNetworks, excludeNetworks, [opts])\n\n- `baseNetworks` *String* or *Array*: One or more CIDR or IP addresses.\n- `excludeNetworks` *String* or *Array*: One or more CIDR or IP addresses to exclude from `baseNetworks`.\n\nReturns an array of merged remaining networks of the subtraction of `excludeNetworks` from `baseNetworks`.\n\n### expandCidr(networks, [opts])\n\n- `networks` *String* or *Array*: One or more CIDR or IP addresses.\n\nReturns a generator for individual IPs contained in the networks.\n\nBe aware that passing large networks that contain millions of IPs can result in memory exhaustion and slow execution time. It's recommended to validate the amount of IPs first, for example, like this:\n\n```js\nimport {parseCidr} from \"cidr-tools\";\n\nconst {start, end} = parseCidr(\"1.2.3.4/2\");\nif (end - start >= 1000000n) {\n  throw new Error(\"Too many IPs\");\n}\n```\n\n### overlapCidr(networksA, networksB, [opts])\n\n- `networksA` *String* or *Array*: One or more CIDR or IP addresses.\n- `networksB` *String* or *Array*: One or more CIDR or IP addresses.\n\nReturns a boolean that indicates if `networksA` overlap (intersect) with `networksB`.\n\n### containsCidr(networksA, networksB, [opts])\n\n- `networksA` *String* or *Array*: One or more CIDR or IP addresses.\n- `networksB` *String* or *Array*: One or more CIDR or IP addresses.\n\nReturns a boolean that indicates whether `networksA` fully contain all `networksB`.\n\n### normalizeCidr(networks, [opts])\n\n- `networks` *String* or *Array*: One or more CIDR or IP addresses.\n\nReturns a string or array (depending on input) with a normalized representation. Will not include a prefix on single IPs. Will set network address to the start of the network.\n\n`opts`: *Object*, additionally to `validate`:\n  - `compress`: Whether to compress the IP. For IPv6, this means the \"best representation\" all-lowercase shortest possible form. Default: `true`.\n  - `hexify`: Whether to convert IPv4-Mapped IPv6 addresses to hex. Default: `false`.\n\n### parseCidr(network, [opts])\n\n- `network` *String*: A CIDR or IP address.\n\nReturns a `parsed` Object which is used internally by this module. It can be used to test whether the passed network is IPv4 or IPv6 or to work with the BigInts directly.\n\n`parsed`: *Object*\n  - `cidr` String: The CIDR of the network.\n  - `ip` String: The IP address inside the CIDR, including any `%scopeid` if present.\n  - `version` Number: IP protocol version. Either `4` or `6`.\n  - `prefix` String: The network prefix, e.g. `64`.\n  - `prefixPresent` Boolean: Whether the passed string has a network prefix.\n  - `start` BigInt: Start number of the network.\n  - `end` BigInt: End number of the network.\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- [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation\n- [cidr-regex](https://github.com/silverwind/cidr-regex) - Regular expression for matching IP addresses in CIDR notation and bare IP addresses\n\n© [silverwind](https://github.com/silverwind), distributed under BSD licence\n","publish_time":1772747954997,"_cnpm_publish_time":1772747954997,"dist-tags":{"latest":"13.0.4"}}