range-parser

中文文档
1.3.0发布于 2026/06/26MIT零依赖近 30 天下载 5.7亿

Range header field string parser

原始使用文档
文档目录4 节
  1. Installation
  2. API
  3. parseRange(size, header, options)
  4. License

range-parser

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Range header field parser.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install range-parser

API

var parseRange = require('range-parser')

parseRange(size, header, options)

Parse the given header string where size is the size of the selected representation that is to be partitioned into subranges. An array of subranges will be returned or negative numbers indicating an error parsing.

  • -2 signals a malformed header string
  • -1 signals an unsatisfiable range
// parse header from request
var subranges = parseRange(size, req.headers.range)

// the type of the subranges
if (subranges.type === 'bytes') {
  // the ranges
  subranges.forEach(function (r) {
    // do something with r.start and r.end
  })
}

Options

These properties are accepted in the options object.

combine

Specifies if overlapping & adjacent subranges should be combined, defaults to false. When true, ranges will be combined and returned as if they were specified that way in the header.

parseRange(100, 'bytes=50-55,0-10,5-10,56-60', { combine: true })
// => [
//      { start: 0,  end: 10 },
//      { start: 50, end: 60 }
//    ]

License

MIT

版本与发布记录

range-parser 共发布 12 个版本,首次发布于 2012/06/12;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.3.0latest2026/06/264 个月前
1.2.12019/05/117 年前
1.2.02016/06/0210 年前
1.1.02016/05/1410 年前
1.0.32015/10/3011 年前
1.0.22014/09/0912 年前

关于 range-parser 的常见问题

range-parser 是什么?

Range header field string parser

如何安装 range-parser?

在项目目录运行 npm install range-parser,或使用 pnpm add / yarn add / bun add。

range-parser 支持 TypeScript 吗?

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

range-parser 需要什么版本的 Node.js?

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

range-parser 可以商用吗?

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

range-parser 的下载量有多少?

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

range-parser 还在维护吗?

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