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

parse-header-stream

v1.1.1

Published

parse http or smtp headers from a stream

Downloads

5

Readme

parse-header-stream

parse http or smtp headers from a stream

build status

example

header example

var parse = require('parse-header-stream');

process.stdin.pipe(parse(function (err, headers) {
    console.log(headers);
}));

Given some email input:

Date: 23 Oct 81 11:22:33
From: [email protected]
To: [email protected]
Subject: Mail System Problem

Sorry JOE, your message to [email protected] lost.

HOSTZ.ARPA said this:
 "550 No Such User"

produces:

{ date: '23 Oct 81 11:22:33',
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Mail System Problem' }

or given some http input:

HTTP/1.1 200 OK
server: ecstatic-0.4.13
etag: "197162-2662-Sun Aug 17 2014 20:53:29 GMT+0000 (UTC)"
last-modified: Sun, 17 Aug 2014 20:53:29 GMT
cache-control: max-age=3600
content-length: 2662
content-type: text/plain; charset=UTF-8
Date: Fri, 29 Aug 2014 10:49:08 GMT
Connection: keep-alive

 45.5%    James Halliday (substack)

    browserify     hyperspace       brfs                   deck
    hacker-deps    trumpet          glog                   hyperquest
    browser-pack   module-deps      insert-module-globals  optimist
...

produces:

{ server: 'ecstatic-0.4.13',
  etag: '"197162-2662-Sun Aug 17 2014 20:53:29 GMT+0000 (UTC)"',
  'last-modified': 'Sun, 17 Aug 2014 20:53:29 GMT',
  'cache-control': 'max-age=3600',
  'content-length': '2662',
  'content-type': 'text/plain; charset=UTF-8',
  date: 'Fri, 29 Aug 2014 10:49:08 GMT',
  connection: 'keep-alive' }

body example

You can also strip the leading headers by listening for the 'body' event:

var parse = require('parse-header-stream');
var p = process.stdin.pipe(parse());
p.on('body', function (body) {
    body.pipe(process.stdout);
});

Given this email data:

Date: 23 Oct 81 11:22:33
From: [email protected]
To: [email protected]
Subject: Mail System Problem

Sorry JOE, your message to [email protected] lost.

HOSTZ.ARPA said this:
 "550 No Such User"

Produces this output:

Sorry JOE, your message to [email protected] lost.

HOSTZ.ARPA said this:
 "550 No Such User"

methods

var parser = require('parse-header-stream')

var stream = parser(opts={}, cb)

Return a writable stream that parses incoming lines for http/email style headers. When the headers are fully read, cb(err, headers) fires with the header fields or an error.

Options are:

  • opts.preserveCase - if true, the cases of keys are preserved instead of being converted to lower-case. Default: false
  • opts.maxLength - maximum size for the entire header payload to be before raising an error event

events

stream.on('header', function (key, value) {})

As each header is parsed, this event fires with the key and value strings.

stream.on('headers', function (headers) {})

stream.on('body', function (body) {})

After the header is parsed, the 'body' event fires with body, a stream with all the raw data after the header.

install

With npm do:

npm install parse-header-stream

license

MIT