# @economist/netparser 中文文档

规范地址：https://npmcn.com/package/%40economist/netparser/

版本：1\.8\.0
npm 元数据更新时间：2026-10-29T04:46:04.415Z
中文译文更新时间：2026-11-13T06:03:35.062Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40economist/netparser
原文对照：https://npmcn.com/package/%40economist/netparser/?lang=original
项目主页：https://github.com/demskie/netparser#readme
源码仓库：https://github.com/EconomistDigitalSolutions/netparser

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：120 kB，39 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2020-08-12T12:00:07.481Z
- 最新版本发布：2020-08-12T12:01:23.521Z
- 近 30 天下载量：2743（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

解析和操纵网络地址

## 安装

```sh
npm install @economist/netparser
```

也可以使用：`pnpm add @economist/netparser`、`yarn add @economist/netparser`、`bun add @economist/netparser`

## README

# 净参数

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

[![Build Status](https://travis-ci.org/demskie/netparser.svg?branch=master)](https://travis-ci.org/demskie/netparser) [![Coverage Status](https://coveralls.io/repos/github/demskie/netparser/badge.svg?branch=master)](https://coveralls.io/github/demskie/netparser?branch=master) [![Dependency Status](https://david-dm.org/demskie/netparser/status.svg)](https://david-dm.org/demskie/netparser#info=dependencies&view=table)

## 安装

```bash
npm install netparser
```

## 实例

```js
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` 在适用的情况下.

## 基准

```bash
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`](https://github.com/charto/docts)

> ### 函数 [`baseAddress`](https://npmcn.com/package/%40economist/netparser/#readme-api-baseAddress)
> 
> _BaseAddress 返回给定子网地址的基址_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L22-L27)
> 
> > **基础地址( )** ⇒ `null | string` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L22-L27)  
> >  \* 网络地址 `string` _\- 网络地址,例如192.168.0.4/24_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`broadcastAddress`](https://npmcn.com/package/%40economist/netparser/#readme-api-broadcastAddress)
> 
> _BradioAddress返回IPv4地址的广播地址._  
> _请注意IPv6没有广播地址._  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L41-L46)
> 
> > **广播地址( )** ⇒ `null | string` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L41-L46)  
> >  \* 网络 `string` _\- 类似192.168.0.0/24的网络_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`findUnusedSubnets`](https://npmcn.com/package/%40economist/netparser/#readme-api-findUnusedSubnets)
> 
> _Find UnusedSubnets 返回未使用子网的数组,考虑到集合和兄弟子网_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L61-L78)
> 
> > **查找未使用的子网( )** ⇒ `null | string[]` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L61-L78)  
> >  合计 `string` _\- 综合网络,如192.168.0.0/24_  
> >  \* 子网 `string[]` _\- 诸如\["192.168.0.0/24","192.168.08.128/26"等子网络阵列_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`ip`](https://npmcn.com/package/%40economist/netparser/#readme-api-ip)
> 
> _解析一个 IP 地址_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L91-L94)
> 
> > **ip () (中文(简体) )** ⇒ `null | string` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L91-L94)  
> >  \* 地址 `string` _\- 地址为192.168.0.0或次网192.168.0.0/24_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`network`](https://npmcn.com/package/%40economist/netparser/#readme-api-network)
> 
> _分析网络地址_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L107-L110)
> 
> > **网络( )** ⇒ `null | string` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L107-L110)  
> >  \* 网络地址 `string` _\- 类似192.168.0.0/24的网络_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`networkComesBefore`](https://npmcn.com/package/%40economist/netparser/#readme-api-networkComesBefore)
> 
> _NetworkComes Before return了数字网络顺序的布尔 ._  
> _请注意,IPv4出现在IPv6之前,而更大的网络出现在较小的网络之前._  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L126-L139)
> 
> > **网络来之前( )** ⇒ `null | true | false` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L126-L139)  
> >  \* 网络 `string` _\- 类似192.168.0.0/24的网络_  
> >  \* 其他网络 `string` _\- 类似192.168.1.0/24的网络_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`networkContainsAddress`](https://npmcn.com/package/%40economist/netparser/#readme-api-networkContainsAddress)
> 
> _网络ContainsAddress 验证地址位于网络内部_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L154-L164)
> 
> > **网络** ⇒ `null | true | false` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L154-L164)  
> >  \* 网络 `string` _\- 类似192.168.0.0/24的网络_  
> >  \* 地址 `string` _\- 类似192.168.0.100的网络_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`networkContainsSubnet`](https://npmcn.com/package/%40economist/netparser/#readme-api-networkContainsSubnet)
> 
> _网络ContainsSubnet验证网络是有效的超级网络_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L179-L185)
> 
> > **网络** ⇒ `null | true | false` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L179-L185)  
> >  \* 网络 `string` _\- 像192.168.0.0/16这样的网络_  
> >  \* 子网 `string` _\- 类似192.168.0.0/24的网络_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`networksIntersect`](https://npmcn.com/package/%40economist/netparser/#readme-api-networksIntersect)
> 
> _网络Intersect 返回显示网络重叠的 bull_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L200-L206)
> 
> > **网络接口( )** ⇒ `null | true | false` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L200-L206)  
> >  \* 网络 `string` _\- 类似192.168.0.0/23的网络_  
> >  \* 其他网络 `string` _\- 类似192.168.1.0/24的网络_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`nextAddress`](https://npmcn.com/package/%40economist/netparser/#readme-api-nextAddress)
> 
> _NextAddress 返回下一个地址_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L219-L227)
> 
> > **下一个地址( )** ⇒ `null | string` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L219-L227)  
> >  \* 地址 `string` _\-一个像192.168.0.0的地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`nextNetwork`](https://npmcn.com/package/%40economist/netparser/#readme-api-nextNetwork)
> 
> _NextNetwork返回大小相同的下个网络._  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L241-L249)
> 
> > **下一个网络( )** ⇒ `null | string` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L241-L249)  
> >  \* 网络 `string` _\- 类似192.168.0.0/24的网络_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`rangeOfNetworks`](https://npmcn.com/package/%40economist/netparser/#readme-api-rangeOfNetworks)
> 
> _RangeOfNetworks 返回一定范围的网络_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L263-L288)
> 
> > **网络范围( )** ⇒ `null | string[]` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L263-L288)  
> >  \* 启动地址 `string` _\- 地址是192.168.1.2号_  
> >  \* 停止定居 `string` _\-一个像192.168.1.5的地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`sort`](https://npmcn.com/package/%40economist/netparser/#readme-api-sort)
> 
> _排序返回一系列排序的网络_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L301-L329)
> 
> > **排序( )** ⇒ `null | string[]` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L301-L329)  
> >  \* 网络地址 `string[]` _\- 一系列地址或子网_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_
> 
> ### 函数 [`summarize`](https://npmcn.com/package/%40economist/netparser/#readme-api-summarize)
> 
> _汇总返回给定网络列表的集合数组_  
> 源代码 : [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L343-L363)
> 
> > **总结( )** ⇒ `null | string[]` [`<>`](http://github.com/demskie/netparser/blob/63db838/src/index.ts#L343-L363)  
> >  • 网络 `string[]` _\- 一系列地址或子网_  
> >  严格? 吗? `undefined | true | false` _\- 不将地址自动遮盖到数据库地址_  
> >  丢出错误? 吗? `undefined | true | false` _\- 阻止图书馆无声失败_

## 常见问题

### @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 和提交记录判断。

