{"_id":"@3-/ip","_rev":"4-bc97f28ece8d2cd6be78ea7b7edd201b","name":"@3-/ip","dist-tags":{"latest":"0.1.4"},"versions":{"0.1.1":{"name":"@3-/ip","version":"0.1.1","keywords":["ip","ipv4","ipv6","binary","converter"],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/ip@0.1.1","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://atomgit.com/i18n/lib/tree/dev/ip","dist":{"shasum":"4671f8b111e3a388635ce605095ccc142345df6f","tarball":"https://registry.npmjs.org/@3-/ip/-/ip-0.1.1.tgz","fileCount":5,"integrity":"sha512-I6FDmxCA2z3tit4zGaQB8ICRMkhk3RtK4JTj0G5ngl7yfaGOt7C8I0bhZO8N64e3SfJvkchhJ7SOysMl1otiGg==","signatures":[{"sig":"MEUCICrCkxYLSNOjjfuM9sYLWvQW5rmQa3TP6szPx/pPttnAAiEAg+hL9tjvroqXueLC7pffj5K1wzrRg3U95DTksLSD7m0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14929},"type":"module","exports":{"./*":"./*"},"gitHead":"833ff4abf54f8d469d41306e4df64b161f436f5a","scripts":{},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://atomgit.com/i18n/lib.git","type":"git"},"_npmVersion":"11.6.2","description":"Bidirectional IP address binary converter / IP 地址二进制双向转换器","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/ip_0.1.1_1763160535224_0.9792662838432178","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@3-/ip","version":"0.1.2","keywords":["ip","ipv4","ipv6","binary","converter"],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/ip@0.1.2","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://atomgit.com/i18n/lib/tree/dev/ip","dist":{"shasum":"221cc9de5ea5761b072fa39ebc33db22ca033638","tarball":"https://registry.npmjs.org/@3-/ip/-/ip-0.1.2.tgz","fileCount":5,"integrity":"sha512-0et77Rd5/M5coAH6Bl9zQvTu3bFIOymuwRX+hBSFINQC2WIONP5m/cTUfKbK5GAuoQ96jXyq56r2CowPkRrpCQ==","signatures":[{"sig":"MEUCIQCxavCAJe8H2IN/MD0x6JJm5A2T+uNh1bbQpTWGUA6P/gIgEKLNSVd/MSOoGogX++ESKC+fxHqVP7GOGgymNSMfHpw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14927},"type":"module","exports":{"./*":"./*"},"gitHead":"1b937b173d12b8d27657056e5795369740982319","scripts":{},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://atomgit.com/i18n/lib.git","type":"git"},"_npmVersion":"11.6.2","description":"Bidirectional IP address binary converter / IP 地址二进制双向转换器","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/ip_0.1.2_1763163946469_0.26291441895825884","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@3-/ip","version":"0.1.3","keywords":["ip","ipv4","ipv6","binary","converter"],"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","_id":"@3-/ip@0.1.3","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"homepage":"https://atomgit.com/i18n/lib/tree/dev/ip","dist":{"shasum":"6361641ec2a6f5172247fa97239dc7577943335f","tarball":"https://registry.npmjs.org/@3-/ip/-/ip-0.1.3.tgz","fileCount":5,"integrity":"sha512-ePEmBJGN+czG+CIuz2A8TUkfGU8n9TCo1mp03XUJihUqj37XCqB3zHP6QDaYEE/XodYNggO4GYlyAPslz8Lh0g==","signatures":[{"sig":"MEUCIQCHeNqSIZ3p7xEwW2H/kAPUs0+/+wev9WanL9Km6e0OyAIgbeoViRm/wF20zU5LiWEj17XJjShM/09XTimXdo5PyP0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13436},"type":"module","exports":{"./*":"./*"},"gitHead":"0c7252fa710454d09d665e61e292c0e164bfead8","scripts":{},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"repository":{"url":"git+https://atomgit.com/i18n/lib.git","type":"git"},"_npmVersion":"11.13.0","description":"Bidirectional IP address binary converter / IP 地址二进制双向转换器","directories":{},"_nodeVersion":"25.4.0","_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/ip_0.1.3_1778668389683_0.5661478403277396","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@3-/ip","version":"0.1.4","keywords":["ip","ipv4","ipv6","binary","converter"],"description":"Bidirectional IP address binary converter / IP 地址二进制双向转换器","repository":{"type":"git","url":"git+https://atomgit.com/i18n/lib.git"},"homepage":"https://atomgit.com/i18n/lib/tree/dev/ip","author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","exports":{"./*":"./*"},"devDependencies":{},"scripts":{},"type":"module","gitHead":"84ae9d9ab87c8dd052f63a15026cacfa1e4e8afc","_id":"@3-/ip@0.1.4","_nodeVersion":"25.4.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-QPLZEizhRutQjxbcWafBvieEjDVwNPOfzDFUHMz2iuk6/R1+lAP1uQ1123/7dQSwsHh93tdCBaKytx1Ka++7WQ==","shasum":"524dabff868142274fa9ed953696578790c67539","tarball":"https://registry.npmjs.org/@3-/ip/-/ip-0.1.4.tgz","fileCount":5,"unpackedSize":13436,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBhYs/fQKqUOvsBHEjHFT4Ntzp+fGCp2S3IcDBLc+pyyAiEAzhL8Lx1+I4lF2vVdqs1H2egE305PFaRMNnbYg9w4/+4="}]},"_npmUser":{"name":"i18n-now","email":"i18n.site@gmail.com"},"directories":{},"maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ip_0.1.4_1778668503653_0.04058220991672057"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-14T22:48:55.106Z","modified":"2026-05-13T10:35:03.920Z","0.1.1":"2025-11-14T22:48:55.431Z","0.1.2":"2025-11-14T23:45:46.655Z","0.1.3":"2026-05-13T10:33:09.868Z","0.1.4":"2026-05-13T10:35:03.814Z"},"author":{"name":"i18n.site@gmail.com"},"license":"MulanPSL-2.0","homepage":"https://atomgit.com/i18n/lib/tree/dev/ip","keywords":["ip","ipv4","ipv6","binary","converter"],"repository":{"type":"git","url":"git+https://atomgit.com/i18n/lib.git"},"description":"Bidirectional IP address binary converter / IP 地址二进制双向转换器","maintainers":[{"name":"i18n-now","email":"i18n.site@gmail.com"}],"readme":"# @3-/ip\n\n[English](#en) | [中文](#zh)\n\n---\n\n<a id=\"en\"></a>\n# @3-/ip : Bidirectional IP Address Binary Converter\n\nHigh-performance library for converting between IP addresses and binary representations, supporting both IPv4 and IPv6 with zero dependencies.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [IPv4 Conversion](#ipv4-conversion)\n  - [IPv6 Conversion](#ipv6-conversion)\n- [Design Philosophy](#design-philosophy)\n- [Technical Stack](#technical-stack)\n- [Project Structure](#project-structure)\n- [API Reference](#api-reference)\n- [Historical Context](#historical-context)\n\n## Features\n\n- **Bidirectional Conversion**: Convert IP addresses to binary and back\n- **Dual Protocol Support**: Full IPv4 and IPv6 compatibility\n- **IPv6 Compression**: Automatic handling of compressed IPv6 notation (::)\n- **Type Safety**: Uses Uint8Array for efficient binary representation\n- **Zero Dependencies**: Pure JavaScript implementation\n- **Modern Syntax**: ES modules with async/await patterns\n\n## Installation\n\n```bash\nbun i @3-/ip\n```\n\n## Usage\n\n### IPv4 Conversion\n\n```javascript\nimport ipBin from '@3-/ip/ipBin.js'\nimport binIp from '@3-/ip/binIp.js'\n\n// Convert IPv4 address to binary\nconst bytes = ipBin('192.168.1.1')\nconsole.log(bytes) // Uint8Array(4) [192, 168, 1, 1]\n\n// Convert binary back to IPv4 address\nconst ip = binIp(bytes)\nconsole.log(ip) // \"192.168.1.1\"\n```\n\n### IPv6 Conversion\n\n```javascript\nimport ipBin from '@3-/ip/ipBin.js'\nimport binIp from '@3-/ip/binIp.js'\n\n// Convert full IPv6 address to binary\nconst bytes = ipBin('2001:0db8:85a3:0000:0000:8a2e:0370:7334')\nconsole.log(bytes) // Uint8Array(16) [32, 1, 13, 184, ...]\n\n// Convert compressed IPv6 address\nconst compressedBytes = ipBin('2001:db8:85a3::8a2e:370:7334')\nconst ip = binIp(compressedBytes)\nconsole.log(ip) // \"2001:db8:85a3::8a2e:370:7334\"\n\n// Handle special addresses\nconst loopback = ipBin('::1')\nconsole.log(binIp(loopback)) // \"::1\"\n```\n\n## Design Philosophy\n\nThe library follows a functional programming approach with two core modules:\n\n**Conversion Flow:**\n\n```\nIP String → ipBin() → Uint8Array → binIp() → IP String\n```\n\n**Module Interaction:**\n\n1. `ipBin.js`: Parses IP string format and converts to binary representation\n   - Detects protocol by delimiter (`:` for IPv6, `.` for IPv4)\n   - Expands compressed IPv6 notation\n   - Validates address format and range\n   - Returns Uint8Array (4 bytes for IPv4, 16 bytes for IPv6)\n\n2. `binIp.js`: Reconstructs IP string from binary data\n   - Determines protocol by array length\n   - Applies IPv6 compression for consecutive zeros\n   - Formats output according to protocol standards\n\n3. `IpInvalid.js`: Centralized error handling for invalid addresses\n\n## Technical Stack\n\n- **Runtime**: Bun/Node.js (ES Modules)\n- **Language**: Modern JavaScript (ES2022+)\n- **Data Structure**: Uint8Array for binary representation\n- **Architecture**: Pure functional programming\n- **Standards**: RFC 4291 (IPv6), RFC 791 (IPv4)\n\n## Project Structure\n\n```\n@3-/ip/\n├── src/\n│   ├── ipBin.js        # IP string to binary converter\n│   ├── binIp.js        # Binary to IP string converter\n│   └── IpInvalid.js    # Error definition\n├── lib/                # Compiled output\n├── test/\n│   └── main.js         # Usage examples and tests\n├── readme/\n│   ├── en.md           # English documentation\n│   └── zh.md           # Chinese documentation\n└── package.json\n```\n\n## API Reference\n\n### ipBin(ip)\n\nConverts IP address string to binary representation.\n\n**Parameters:**\n- `ip` (string): IPv4 or IPv6 address\n\n**Returns:**\n- `Uint8Array`: 4 bytes for IPv4, 16 bytes for IPv6\n\n**Throws:**\n- `IpInvalid`: When address format is invalid\n\n### binIp(bin)\n\nConverts binary representation to IP address string.\n\n**Parameters:**\n- `bin` (Uint8Array): Binary IP address (4 or 16 bytes)\n\n**Returns:**\n- `string`: Formatted IP address\n\n**Throws:**\n- `IpInvalid`: When binary length is invalid\n\n## Historical Context\n\nThe need for IP address binary conversion emerged from the early days of network programming. In 1981, RFC 791 defined IPv4 with its 32-bit address space, using dot-decimal notation for human readability while computers processed addresses as binary data.\n\nAs the internet grew, IPv4's 4.3 billion addresses proved insufficient. RFC 2460 introduced IPv6 in 1998, expanding to 128-bit addresses with hexadecimal colon notation. The double-colon (::) compression syntax was added to simplify the lengthy addresses, creating the challenge this library solves: efficiently converting between human-readable and machine-processable formats.\n\nThe choice of Uint8Array reflects modern JavaScript's evolution. Before typed arrays were introduced in ES2015, developers relied on regular arrays or Buffer objects, which were less efficient for binary operations. Uint8Array provides direct memory access and better performance for network-level operations, making it the ideal choice for IP address manipulation in contemporary JavaScript applications.\n\n---\n\n<a id=\"zh\"></a>\n# @3-/ip : IP 地址二进制双向转换器\n\n高性能 IP 地址与二进制表示相互转换库，支持 IPv4 和 IPv6，零依赖。\n\n## 目录\n\n- [特性](#特性)\n- [安装](#安装)\n- [使用方法](#使用方法)\n  - [IPv4 转换](#ipv4-转换)\n  - [IPv6 转换](#ipv6-转换)\n- [设计思路](#设计思路)\n- [技术栈](#技术栈)\n- [项目结构](#项目结构)\n- [API 参考](#api-参考)\n- [历史背景](#历史背景)\n\n## 特性\n\n- **双向转换**：IP 地址与二进制格式互相转换\n- **双协议支持**：完整支持 IPv4 和 IPv6\n- **IPv6 压缩**：自动处理 IPv6 压缩表示法（::）\n- **类型安全**：使用 Uint8Array 高效表示二进制数据\n- **零依赖**：纯 JavaScript 实现\n\n## 安装\n\n```bash\nbun i @3-/ip\n```\n\n## 使用方法\n\n### IPv4 转换\n\n```javascript\nimport ipBin from '@3-/ip/ipBin.js'\nimport binIp from '@3-/ip/binIp.js'\n\n// 将 IPv4 地址转换为二进制\nconst bytes = ipBin('192.168.1.1')\nconsole.log(bytes) // Uint8Array(4) [192, 168, 1, 1]\n\n// 将二进制转换回 IPv4 地址\nconst ip = binIp(bytes)\nconsole.log(ip) // \"192.168.1.1\"\n```\n\n### IPv6 转换\n\n```javascript\nimport ipBin from '@3-/ip/ipBin.js'\nimport binIp from '@3-/ip/binIp.js'\n\n// 将完整 IPv6 地址转换为二进制\nconst bytes = ipBin('2001:0db8:85a3:0000:0000:8a2e:0370:7334')\nconsole.log(bytes) // Uint8Array(16) [32, 1, 13, 184, ...]\n\n// 转换压缩格式的 IPv6 地址\nconst compressedBytes = ipBin('2001:db8:85a3::8a2e:370:7334')\nconst ip = binIp(compressedBytes)\nconsole.log(ip) // \"2001:db8:85a3::8a2e:370:7334\"\n\n// 处理特殊地址\nconst loopback = ipBin('::1')\nconsole.log(binIp(loopback)) // \"::1\"\n```\n\n## 设计思路\n\n本库采用函数式编程方法，由两个核心模块组成：\n\n**转换流程：**\n\n```\nIP 字符串 → ipBin() → Uint8Array → binIp() → IP 字符串\n```\n\n**模块调用关系：**\n\n1. `ipBin.js`：解析 IP 字符串格式并转换为二进制表示\n   - 通过分隔符检测协议（`:` 表示 IPv6，`.` 表示 IPv4）\n   - 展开 IPv6 压缩表示法\n   - 验证地址格式和范围\n   - 返回 Uint8Array（IPv4 为 4 字节，IPv6 为 16 字节）\n\n2. `binIp.js`：从二进制数据重建 IP 字符串\n   - 根据数组长度判断协议类型\n   - 对连续的零应用 IPv6 压缩\n   - 按协议标准格式化输出\n\n3. `IpInvalid.js`：集中处理无效地址错误\n\n## 技术栈\n\n- **运行时**：Bun/Node.js（ES 模块）\n- **语言**：现代 JavaScript（ES2022+）\n- **数据结构**：Uint8Array 二进制表示\n- **架构**：纯函数式编程\n- **标准**：RFC 4291（IPv6）、RFC 791（IPv4）\n\n## 项目结构\n\n```\n@3-/ip/\n├── src/\n│   ├── ipBin.js        # IP 字符串转二进制转换器\n│   ├── binIp.js        # 二进制转 IP 字符串转换器\n│   └── IpInvalid.js    # 错误定义\n├── lib/                # 编译输出\n├── test/\n│   └── main.js         # 使用示例和测试\n├── readme/\n│   ├── en.md           # 英文文档\n│   └── zh.md           # 中文文档\n└── package.json\n```\n\n## API 参考\n\n### ipBin(ip)\n\n将 IP 地址字符串转换为二进制表示。\n\n**参数：**\n- `ip` (string)：IPv4 或 IPv6 地址\n\n**返回值：**\n- `Uint8Array`：IPv4 为 4 字节，IPv6 为 16 字节\n\n**抛出异常：**\n- `IpInvalid`：地址格式无效时\n\n### binIp(bin)\n\n将二进制表示转换为 IP 地址字符串。\n\n**参数：**\n- `bin` (Uint8Array)：二进制 IP 地址（4 或 16 字节）\n\n**返回值：**\n- `string`：格式化的 IP 地址\n\n**抛出异常：**\n- `IpInvalid`：二进制长度无效时\n\n## 历史背景\n\nIP 地址二进制转换的需求源于网络编程的早期发展。1981 年，RFC 791 定义了 IPv4 及其 32 位地址空间，采用点分十进制记法便于人类阅读，而计算机则以二进制数据处理地址。\n\n随着互联网的发展，IPv4 的 43 亿地址空间逐渐不足。1998 年，RFC 2460 引入了 IPv6，将地址扩展到 128 位，采用十六进制冒号记法。双冒号（::）压缩语法的加入简化了冗长的地址表示，但也带来了本库要解决的挑战：在人类可读格式和机器可处理格式之间高效转换。\n\n选择 Uint8Array 反映了现代 JavaScript 的演进。在 ES2015 引入类型化数组之前，开发者依赖普通数组或 Buffer 对象，这些方式在二进制操作上效率较低。Uint8Array 提供直接内存访问和更好的性能，使其成为当代 JavaScript 应用中进行网络层级操作的理想选择。\n\n---\n\n## About\n\nThis project is an open-source component of [i18n.site ⋅ Internationalization Solution](https://i18n.site).\n\n* [i18 : MarkDown Command Line Translation Tool](https://i18n.site/i18)\n\n  The translation perfectly maintains the Markdown format.\n\n  It recognizes file changes and only translates the modified files.\n\n  The translated Markdown content is editable; if you modify the original text and translate it again, manually edited translations will not be overwritten (as long as the original text has not been changed).\n\n* [i18n.site : MarkDown Multi-language Static Site Generator](https://i18n.site/i18n.site)\n\n  Optimized for a better reading experience\n\n## 关于\n\n本项目为 [i18n.site ⋅ 国际化解决方案](https://i18n.site) 的开源组件。\n\n* [i18 :  MarkDown命令行翻译工具](https://i18n.site/i18)\n\n  翻译能够完美保持 Markdown 的格式。能识别文件的修改，仅翻译有变动的文件。\n\n  Markdown 翻译内容可编辑；如果你修改原文并再次机器翻译，手动修改过的翻译不会被覆盖（如果这段原文没有被修改）。\n\n* [i18n.site : MarkDown多语言静态站点生成器](https://i18n.site/i18n.site) 为阅读体验而优化。\n","readmeFilename":"README.md"}