{"name":"ip-bigint","version":"9.0.2","keywords":["ip","ipv4","ipv6","bigint","address","parse","stringify","normalize","convert","rfc5952","rfc4291"],"author":{"name":"silverwind","email":"me@silverwind.io"},"license":"BSD-2-Clause","_id":"ip-bigint@9.0.2","maintainers":[{"name":"silverwind","email":"npm@silverwind.io"}],"homepage":"https://github.com/silverwind/ip-bigint#readme","bugs":{"url":"https://github.com/silverwind/ip-bigint/issues"},"dist":{"shasum":"43ad5022b3184f1e6dd87f8b67c99cb9aff91ef5","tarball":"http://registry-npm.ywwl.com/ip-bigint/download/ip-bigint-9.0.2.tgz","fileCount":5,"integrity":"sha512-WSu12//cz6bLVSYtLX/pCwukLEapUGnA7IYIQvrlrvAucxwt5reifGmTfXJ+sEB3zUesC2k9tfDaB4X+M+LjQA==","signatures":[{"sig":"MEQCICdbUwLvvjWTOOVlghmOhanpm0M63YznvQRJKs3j4LddAiBT1bvaHWGrx2G5upCDBLg17q21y1iZQoOjLs1nXVhuvQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/ip-bigint@9.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":16275,"size":5398,"noattachment":false,"key":"/ip-bigint/-/ip-bigint-9.0.2.tgz"},"main":"./dist/index.js","type":"module","_from":"file:ip-bigint-9.0.2.tgz","types":"./dist/index.d.ts","engines":{"bun":"*","node":">=22"},"exports":"./dist/index.js","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3867e8da-2344-474a-a6e8-ecfb61989f58"}},"_resolved":"/tmp/88b61a89118a3725207c862950ff42ca/ip-bigint-9.0.2.tgz","_integrity":"sha512-WSu12//cz6bLVSYtLX/pCwukLEapUGnA7IYIQvrlrvAucxwt5reifGmTfXJ+sEB3zUesC2k9tfDaB4X+M+LjQA==","repository":{"url":"git+https://github.com/silverwind/ip-bigint.git","type":"git"},"_npmVersion":"11.13.0","description":"Convert IPv4 and IPv6 addresses to and from BigInt","directories":{},"sideEffects":false,"_nodeVersion":"26.1.0","_hasShrinkwrap":false,"devDependencies":{"eslint":"10.4.0","tsdown":"0.22.0","vitest":"4.1.6","updates":"17.16.12","versions":"15.0.4","typescript":"6.0.3","@types/node":"25.8.0","jest-extended":"7.0.0","@vitest/coverage-v8":"4.1.6","eslint-config-silverwind":"133.0.3","tsdown-config-silverwind":"3.0.1","vitest-config-silverwind":"11.3.5","updates-config-silverwind":"3.0.2","@typescript/native-preview":"7.0.0-dev.20260516.1","typescript-config-silverwind":"18.0.0"},"_npmOperationalInternal":{"tmp":"tmp/ip-bigint_9.0.2_1778993150430_0.08803519818120242","host":"s3://npm-registry-packages-npm-production"},"readme":"# ip-bigint\n[![](https://img.shields.io/npm/v/ip-bigint.svg?style=flat)](https://www.npmjs.org/package/ip-bigint) [![](https://img.shields.io/npm/dm/ip-bigint.svg)](https://www.npmjs.org/package/ip-bigint) [![](https://img.shields.io/bundlephobia/minzip/ip-bigint.svg)](https://bundlephobia.com/package/ip-bigint) [![](https://packagephobia.com/badge?p=ip-bigint)](https://packagephobia.com/result?p=ip-bigint) [![](https://depx.co/api/badge/ip-bigint)](https://depx.co/pkg/ip-bigint)\n\n> Convert IPv4 and IPv6 addresses to and from BigInt. Compliant with [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952) and [RFC 4291](https://datatracker.ietf.org/doc/html/rfc4291).\n\n## Usage\n\n```sh\npnpm add ip-bigint\n```\n\n```js\nimport {parseIp, stringifyIp, normalizeIp} from \"ip-bigint\";\n\nconst parsedIp = parseIp(\"2001:db8::\");\n// => {number: 42540766411282592856903984951653826560n, version: 6}\n\nstringifyIp(parsedIp);\n// => \"2001:db8::\"\n\nnormalizeIp(\"2001:db8::0:0:1\");\n// => \"2001:db8::1\"\n```\n\n## API\n\n### parseIp(ip: string, opts?: ParseOpts)\n\nParse an IP address string to a `ParsedIP` object. Throws if the string is not a valid IP address.\n\nFor IPv4 returns `{number, version}`.\nFor IPv6 returns `{number, version, [ipv4mapped], [scopeid]}`.\n\n`opts`: Options `ParseOpts`\n  - `validate`: boolean - Whether to reject strings that are not well-formed IP addresses. Default: `true`.\n\nValidation uses [cidr-regex](https://github.com/silverwind/cidr-regex), so it follows the addressing rules: zero-padded IPv4 octets (`01.02.03.04`), IPv6 groups longer than four hex digits, and empty or otherwise malformed scope ids are all rejected. Versions before 10 accepted these and parsed them leniently.\n\nPassing `validate: false` skips the check for input already known to be valid, at the cost of the guarantee: malformed input is then parsed on a best-effort basis and can produce an IPv4 number above `max4`.\n\n### stringifyIp({number, version, [ipv4mapped], [scopeid]}: ParsedIP, opts?: StringifyOpts)\n\nConvert a `ParsedIP` object back to an IP address string.\n\n`opts`: Options `StringifyOpts`\n  - `compress`: boolean - Whether to compress the IP. For IPv6, this means the \"best representation\" all-lowercase shortest possible form. Default: `true`.\n  - `hexify`: boolean - Whether to convert IPv4-Mapped IPv6 addresses to hex. Default: `false`.\n  - `mapv4`: boolean - Whether to convert IPv4-Mapped IPv6 addresses (e.g. `::ffff:127.0.0.1`) to plain IPv4 (e.g. `127.0.0.1`). Default: `false`.\n\n### normalizeIp(ip: string, opts?: NormalizeOpts)\n\nRound-trip an IP address through `parseIp` and `stringifyIp`, effectively normalizing its representation.\n\n`opts`: Options `NormalizeOpts`, which is `validate` plus every `StringifyOpts` key, as documented above.\n\n### max4\n\nA `bigint` value that holds the biggest possible IPv4 address.\n\n### max6\n\nA `bigint` value that holds the biggest possible IPv6 address.\n\n### ipVersion(ip: string)\n\nReturns an integer of the IP version, 4, 6 or 0 if it's not a valid IP address. Before version 10 this only looked for the first `.` or `:`, so it reported a version for malformed strings like `999.1.1.1`, which now return 0.\n\n## Related\n\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- [cidr-tools](https://github.com/silverwind/cidr-tools) - Tools to work with IPv4 and IPv6 CIDR network lists\n\n© [silverwind](https://github.com/silverwind), distributed under BSD licence\n","publish_time":1778993150567,"_cnpm_publish_time":1778993150567,"dist-tags":{"latest":"10.0.4"}}