@economist/netparser

中文文档
1.8.0发布于 2020/08/12MITTypeScriptCommonJS零依赖近 30 天下载 2743

解析和操纵网络地址

中文使用文档
文档目录20 节
  1. 分析并操纵 IPv4 和 IPv6 网络地址
  2. 安装
  3. 实例
  4. 报告
  5. 基准
  6. API 密码
  7. 函数 baseAddress
  8. 函数 broadcastAddress
  9. 函数 findUnusedSubnets
  10. 函数 ip
  11. 函数 network
  12. 函数 networkComesBefore
  13. 函数 networkContainsAddress
  14. 函数 networkContainsSubnet
  15. 函数 networksIntersect
  16. 函数 nextAddress
  17. 函数 nextNetwork
  18. 函数 rangeOfNetworks
  19. 函数 sort
  20. 函数 summarize

净参数

分析并操纵 IPv4 和 IPv6 网络地址

Build Status Coverage Status Dependency Status

安装

npm install netparser

实例

import * as netparser from 'netparser';

netparser.baseAddress('b011:a2c2:7328:cc01:4ee7:e2ec:6269:babf/73');
// returns 'b011:a2c2:7328:cc01:4e80::'

netparser.broadcastAddress('192.168.0.50/24');
// returns '192.168.0.255'

netparser.findUnusedSubnets('192.168.0.0/22', ['192.168.1.0/24', '192.168.2.32/30']);
// returns ['192.168.0.0/24', '192.168.2.0/27', '192.168.2.36/30', '192.168.2.40/29', '192.168.2.48/28', '192.168.2.64/26', '192.168.2.128/25', '192.168.3.0/24']

netparser.ip(' [2001:db8:122:344:0:0:0::0:0:0:1] ');
// returns '2001:db8:122:344::1'

netparser.network(' 192.168.000.000/24 ');
// returns '192.168.0.0/24'

netparser.networkComesBefore('192.168.0.0/24', '10.0.0.0/8');
// returns false

netparser.networkContainsSubnet('192.168.0.0/16', '192.168.0.0/24');
// returns true

netparser.networksIntersect('192.168.0.0/23', '192.168.1.0/24');
// returns true

netparser.nextAddress('192.168.0.0');
// returns '192.168.0.1'

netparser.nextNetwork('192.168.0.0/24');
// returns '192.168.1.0/24'

netparser.rangeOfNetworks('192.168.1.2', '192.168.2.2');
// returns ['192.168.1.2/31', '192.168.1.4/30', '192.168.1.8/29', '192.168.1.16/28', '192.168.1.32/27', '192.168.1.64/26', '192.168.1.128/25', '192.168.2.0/31', '192.168.2.2/32']

netparser.sort(['255.255.255.255', '192.168.0.0/16', '192.168.2.3/31']);
// returns ['192.168.0.0/16', '192.168.2.3/31', '255.255.255.255/32']

netparser.summarize(['192.168.1.1', '192.168.0.0/16', '192.168.2.3/31']);
// returns ['192.168.0.0/16']

var matcher = new netparser.Matcher(['192.168.0.0/24', '192.168.2.0/23', '192.168.4.0/24']);
matcher.has('192.168.3.0');
// returns true

报告

  • 简而言之,所有功能都只能回归 String, String[], boolean, or null。 。 。 .
  • 默认情况下,库将无声地失败 null 当遇到错误时返回。 要覆盖此设置可选 throwErrors 参数改为 True。 。 。 .
  • 默认情况下, 库会方便地遮盖 network 当这样的操作有道理时,数值会输入其基本地址。 要覆盖此设置可选 strict 参数改为 True 在适用的情况下.

基准

npm run bench

'index.bench.ts' output:
    baseAddress (netparser)        x 1,881,378 ops/sec ±0.66% (95 runs sampled)
    baseAddress (ip-address)       x 1,355,975 ops/sec ±0.64% (88 runs sampled)
    baseAddress (ipaddr.js)        x 509,825 ops/sec ±2.07% (89 runs sampled)
    baseAddress (netmask)          x 326,042 ops/sec ±3.84% (82 runs sampled)
    contains (netparser)           x 883,418 ops/sec ±1.53% (84 runs sampled)
    contains (ip-address)          x 901,704 ops/sec ±1.44% (90 runs sampled)
    contains (ipaddr.js)           x 59,005 ops/sec ±13.38% (65 runs sampled)
    contains (netmask)             x 304,785 ops/sec ±1.77% (88 runs sampled)

'match.bench.ts' output:
    create (netparser)             x 11.91 ops/sec ±5.55% (34 runs sampled)
    create (cidr-matcher)          x 5.13 ops/sec ±5.43% (17 runs sampled)
    create (ipaddr.js)             x 28.78 ops/sec ±4.83% (50 runs sampled)
    query (netparser)              x 145,604 ops/sec ±1.25% (91 runs sampled)
    query (cidr-matcher)           x 1,035 ops/sec ±3.74% (83 runs sampled)
    query (ipaddr.js)              x 16.22 ops/sec ±1.76% (44 runs sampled)

API 密码

使用 docts

函数 baseAddress

BaseAddress 返回给定子网地址的基址
源代码 : <>

基础地址( ) ⇒ null | string <>
 * 网络地址 string - 网络地址,例如192.168.0.4/24
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 broadcastAddress

BradioAddress返回IPv4地址的广播地址.
请注意IPv6没有广播地址.
源代码 : <>

广播地址( ) ⇒ null | string <>
 * 网络 string - 类似192.168.0.0/24的网络
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 findUnusedSubnets

Find UnusedSubnets 返回未使用子网的数组,考虑到集合和兄弟子网
源代码 : <>

查找未使用的子网( ) ⇒ null | string[] <>
 合计 string - 综合网络,如192.168.0.0/24
 * 子网 string[] - 诸如["192.168.0.0/24","192.168.08.128/26"等子网络阵列
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 ip

解析一个 IP 地址
源代码 : <>

ip () (中文(简体) ) ⇒ null | string <>
 * 地址 string - 地址为192.168.0.0或次网192.168.0.0/24
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 network

分析网络地址
源代码 : <>

网络( ) ⇒ null | string <>
 * 网络地址 string - 类似192.168.0.0/24的网络
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 networkComesBefore

NetworkComes Before return了数字网络顺序的布尔 .
请注意,IPv4出现在IPv6之前,而更大的网络出现在较小的网络之前.
源代码 : <>

网络来之前( ) ⇒ null | true | false <>
 * 网络 string - 类似192.168.0.0/24的网络
 * 其他网络 string - 类似192.168.1.0/24的网络
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 networkContainsAddress

网络ContainsAddress 验证地址位于网络内部
源代码 : <>

网络 ⇒ null | true | false <>
 * 网络 string - 类似192.168.0.0/24的网络
 * 地址 string - 类似192.168.0.100的网络
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 networkContainsSubnet

网络ContainsSubnet验证网络是有效的超级网络
源代码 : <>

网络 ⇒ null | true | false <>
 * 网络 string - 像192.168.0.0/16这样的网络
 * 子网 string - 类似192.168.0.0/24的网络
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 networksIntersect

网络Intersect 返回显示网络重叠的 bull
源代码 : <>

网络接口( ) ⇒ null | true | false <>
 * 网络 string - 类似192.168.0.0/23的网络
 * 其他网络 string - 类似192.168.1.0/24的网络
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 nextAddress

NextAddress 返回下一个地址
源代码 : <>

下一个地址( ) ⇒ null | string <>
 * 地址 string -一个像192.168.0.0的地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 nextNetwork

NextNetwork返回大小相同的下个网络.
源代码 : <>

下一个网络( ) ⇒ null | string <>
 * 网络 string - 类似192.168.0.0/24的网络
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 rangeOfNetworks

RangeOfNetworks 返回一定范围的网络
源代码 : <>

网络范围( ) ⇒ null | string[] <>
 * 启动地址 string - 地址是192.168.1.2号
 * 停止定居 string -一个像192.168.1.5的地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 sort

排序返回一系列排序的网络
源代码 : <>

排序( ) ⇒ null | string[] <>
 * 网络地址 string[] - 一系列地址或子网
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

函数 summarize

汇总返回给定网络列表的集合数组
源代码 : <>

总结( ) ⇒ null | string[] <>
 • 网络 string[] - 一系列地址或子网
 严格? 吗? undefined | true | false - 不将地址自动遮盖到数据库地址
 丢出错误? 吗? undefined | true | false - 阻止图书馆无声失败

版本与发布记录

@economist/netparser 共发布 2 个版本,首次发布于 2020/08/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.8.0latest2020/08/126 年前
1.7.02020/08/126 年前

关于 @economist/netparser 的常见问题

@economist/netparser 是什么?

解析和操纵网络地址

如何安装 @economist/netparser?

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

@economist/netparser 支持 TypeScript 吗?

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

@economist/netparser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@economist/netparser 可以商用吗?

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

@economist/netparser 的下载量有多少?

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

@economist/netparser 还在维护吗?

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