npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-range

v1.0.0

Published

Node.js parser for Content-Range and Range HTTP/1.1 header fields.

Downloads

6,880

Readme

http-range

Node.js parser for Content-Range and Range HTTP header fields according to the HTTP/1.1 specifications.

Build Status

Installation

$ npm install http-range

Usage

var ContentRange = require('http-range').ContentRange;
var Range = require('http-range').Range;

// Parsing and creating 'Content-Range' header
ContentRange.prototype.parse('bytes 0-49/50');  // Content-Range: bytes 0-49/50
new ContentRange('bytes', '0-49', 50).toString(); // => bytes 0-49/50

// Parsing and creating 'Range' header
Range.prototype.parse('bytes=0-49');  // Range: bytes=0-49
new Range('bytes', '0-49'); // => bytes=0-49

For more usages check the test files.

API

ContentRange Class

new ContentRange(unit, range, length)
  • unit {String} Usually 'bytes', but can be any token
  • range {RangeSpec|String} A RangeSpec instance, a string like '0-49' or '*' if unknown
  • length {Number|'*'} The total length of the full entity-body or '*' if this length is unknown or difficult to determine

Throws error if arguments are invalid.

Properties
  • unit {String}
  • range {RangeSpec}
  • length {Number|null} Null if unknown
Methods
  • toString() Return a valid string value
  • parse(input) Parse an input string. Throws error if invalid

Allowed Content-Range(s)

  • Content-Range: bytes 0-49/50
  • Content-Range: bytes 0-49/*
  • Content-Range: bytes */50
  • Content-Range: bytes */*

Range Class

new Range(unit, ranges)
  • unit {String} Usually 'bytes', but can be any token
  • ranges {RangeSpec[]|String} An array of RangeSpec instances or a string like '0-49[,50-99][...]'

Throws error if arguments are invalid.

Properties
Methods
  • toString() Return a valid string value
  • parse(input) Parse an input string. Throws error if invalid

Allowed Range(s)

  • Range: bytes=0-49
  • Range: bytes=0-49,50-99,-30
  • Range: bytes=1-
  • Range: bytes=-50

RangeSpec Class

new RangeSpec(low, high, size)
  • low {Number|undefined}
  • high {Number|undefined}
  • size {Number|undefined} For validation only, optional

Throws error if arguments are invalid.

Properties
  • low {Number|undefined}
  • high {Number|undefined}
Methods
  • toString() Return a valid string value
  • parse(input) Parse an input string. Throws error if invalid

Examples of valid ranges

  • *
  • 0-49
  • -49
  • 34-

Tests

$ make test