@cloudron/ipaddr

中文文档
1.1.0发布于 2026/06/04ISCES Module零依赖近 30 天下载 5217

IP address and CIDR helpers

原始使用文档
文档目录9 节
  1. Install
  2. Usage
  3. API
  4. isValid(ip)
  5. parseCIDR(cidr)
  6. isValidCIDR(cidr)
  7. isEqual(ip1, ip2)
  8. includes(cidr, ip)
  9. Notes

@cloudron/ipaddr

Small IP address and CIDR helpers used by Cloudron services.

Install

npm install @cloudron/ipaddr

Usage

import ipaddr, { isValid, isValidCIDR, isEqual, includes, parseCIDR } from '@cloudron/ipaddr';

isValid('1.2.3.4'); // true
isValidCIDR('172.18.0.0/16'); // true
isEqual('::ffff:1.2.3.4', '1.2.3.4'); // true
includes('10.0.0.0/8', '10.1.2.3'); // true
parseCIDR('172.18.0.0/16'); // { ip: '172.18.0.0', prefix: 16, family: 4 }

// default export has the same helpers
ipaddr.isValid('::1'); // true

API

isValid(ip)

Returns true if ip is a valid IPv4 or IPv6 address, otherwise false.

parseCIDR(cidr)

Parses a CIDR string and returns { ip, prefix, family } (family is 4 or 6).

Returns null for invalid CIDR input.

isValidCIDR(cidr)

Returns true if cidr is a valid CIDR string (IPv4 or IPv6), otherwise false.

isEqual(ip1, ip2)

Compares two IP addresses and returns true if they represent the same address.

This normalizes different textual forms (for example IPv6 shorthand and IPv4-mapped IPv6).

includes(cidr, ip)

Returns true if ip is inside the provided cidr range, otherwise false.

Notes

  • All functions expect string inputs.
  • Invalid values return false for validation and comparison checks.
  • Both named exports and default export are supported.

版本与发布记录

@cloudron/ipaddr 共发布 2 个版本,首次发布于 2026/06/04;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.1.0latest2026/06/045 个月前
1.0.02026/06/045 个月前

关于 @cloudron/ipaddr 的常见问题

@cloudron/ipaddr 是什么?

IP address and CIDR helpers

如何安装 @cloudron/ipaddr?

在项目目录运行 npm install @cloudron/ipaddr,或使用 pnpm add / yarn add / bun add。

@cloudron/ipaddr 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cloudron__ipaddr 是否存在。

@cloudron/ipaddr 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cloudron/ipaddr 可以商用吗?

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

@cloudron/ipaddr 的下载量有多少?

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

@cloudron/ipaddr 还在维护吗?

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