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

fringe

v1.1.1

Published

Fast, lightweight, and extensible message framing over streams

Downloads

43

Readme

Fringe

Build Status

Fast, lightweight, and extensible message framing over streams.

Installing

npm install --save fringe

Usage

By default, fringe encodes your input buffer with the string FRINGE plus the byte length of the input buffer encoded as UInt32BE.

Hello world:

const { Encoder, Parser } = require('fringe');

const encoder = new Encoder();
const parser  = new Parser();

encoder.pipe( parser );

parser.on( 'message', buffer => console.log( buffer.toString('utf8') ) );

encoder.write('hello');
encoder.write('world');

Events

When a complete message is received, Parser will emit two events:

data

The standard Node.js data events for streams. The argument passed to your callback will be a Buffer of the original message payload.

message

The argument passed to the message event will be the return value of the Parser instance's translate method (see below).

By default, this value will be identical to the Buffer passed to the data callback – but is useful for situations where translate may return a parsed object.

Configuration

Encoder and Parser each accept two arguments:

format

An object containing formatting options for the message

prefix

A string that will be prepended to each message (may be an empty string). Defaults to FRINGE.

lengthFormat

The binary format that the payload length will be stored as. Options are UInt8, UInt16BE, UInt16LE, UInt32BE, and UInt32LE. Defaults to UInt32BE.

maxSize

The maximum acceptable payload length in bytes. Defaults to 100 MB (1024 * 1024 * 100).

options

Options to be passed directly to the underlying Transform stream.

Extending

Encoder and Parser may each be sub-classes with custom translate methods.

Encoder translate

Accepts any value and must return a string or Buffer.

An example translate function to accept an object and output a JSON string:

translate( obj ) {
  return JSON.stringify( obj );
}

Parser translate

Accepts a string or Buffer and may return any value.

An example translate function to accept a Buffer and output an object:

translate( buffer ) {
  return JSON.parse( buffer.toString('utf8') );
}