@achingbrain/ip-address

中文文档
8.1.0发布于 2022/01/06MITTypeScriptESM + CJS近 30 天下载 1.1万

A library for parsing IPv4 and IPv6 IP addresses in node and the browser.

原始使用文档
文档目录6 节
  1. ip-address
  2. Migrating from 6.x to 7.x
  3. Documentation
  4. Examples
  5. Features
  6. Used by

Temporary fork of ip-address with #148 applied

travis codecov downloads npm snyk

ip-address

ip-address is a library for validating and manipulating IPv4 and IPv6 addresses in JavaScript.

Migrating from 6.x to 7.x

ip-address was rewritten in TypeScript for version 7. If you were using version 6 you'll need to make these changes to upgrade:

  • Instead of checking isValid(), which has been removed, you'll need to use a try/catch if you're accepting unknown input. This made the TypeScript types substantially easier as well as allowed the use of an AddressError class which will contain a parseMessage if an error occurred in the parsing step.
  • Instead of using the error, parseError, and valid attributes you'll need to use the message and parseMessage of the thrown AddressError.

Documentation

Documentation is available at ip-address.js.org.

Examples

var Address6 = require('ip-address').Address6;

var address = new Address6('2001:0:ce49:7601:e866:efff:62c3:fffe');

var teredo = address.inspectTeredo();

teredo.client4;    // '157.60.0.1'

Features

  • Usable via CommonJS or ESM
  • Parsing of all IPv6 notations
  • Parsing of IPv6 addresses and ports from URLs with Address6.fromURL(url)
  • Validity checking
  • Decoding of the Teredo information in an address
  • Whether one address is a valid subnet of another
  • What special properties a given address has (multicast prefix, unique local address prefix, etc.)
  • Number of subnets of a certain size in a given address
  • Display methods
    • Hex, binary, and decimal
    • Canonical form
    • Correct form
    • IPv4-compatible (i.e. ::ffff:192.168.0.1)
  • Works in node and the browser (with browserify)
  • ~1,600 test cases

Used by

版本与发布记录

@achingbrain/ip-address 共发布 1 个版本,首次发布于 2022/01/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
8.1.0latest2022/01/064 年前

关于 @achingbrain/ip-address 的常见问题

@achingbrain/ip-address 是什么?

A library for parsing IPv4 and IPv6 IP addresses in node and the browser.

如何安装 @achingbrain/ip-address?

在项目目录运行 npm install @achingbrain/ip-address,或使用 pnpm add / yarn add / bun add。

@achingbrain/ip-address 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@achingbrain/ip-address 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@achingbrain/ip-address 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@achingbrain/ip-address 可以商用吗?

@achingbrain/ip-address 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@achingbrain/ip-address 的下载量有多少?

根据 npm 官方下载统计,@achingbrain/ip-address 在 2026/10/05 – 2026/11/03 这 30 天内被下载 10,844 次,日均约 361 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@achingbrain/ip-address 还在维护吗?

最新版本 8.1.0 发布于 2022/01/06(4 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/01/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。