New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

range-parsest

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

range-parsest

Rewrite of the original range-parser package

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

range-parsest

Range header field parser.

Installation

You can install range-parsest through NPM:

npm i range-parser

Methods

import { parse } from "range-parsest";

parse(size, header, options)

Parse the given header string where size is the size of the selected representation that is to be partitioned into subranges. A ParseResult will be returned.

Example ParseResult:

// A file of size 255 and a header requesting the first 100 bytes.
const result = parse(255, "bytes=0-100");
// Result is
({
  type: "bytes",
  ranges: [{ start: 0, end: 100 }],
  rangeCount: 1,
});

You can use a destructuring assignment to get these values quickly. For example:

// parse header from request
const { type, ranges } = parse(size, req.headers.range);

// the type of the subranges
if (type === "bytes") {
  for (const { start, end } of ranges) {
    // do something with start and end
  }
}
parseCompat
This function only exists for easy switching to range-parsest, please use the normal parse() method instead.

This function is fully compatible with the original range-parser's parseRange. You use the exact same API, but instead of importing it as

var parseRange = require("range-parser");

you import it as

import { parseCompat as parseRange } from "range-parsest";
ParseOptions

These properties are accepted in the options parameter of the parse function:

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 });
// Results in
({
  type: "bytes",
  ranges: [
    { start: 50, end: 55 },
    { start: 0, end: 10 },
    { start: 50, end: 60 },
  ],
  rangeCount: 3,
});

License

MIT

Keywords

FAQs

Package last updated on 17 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc