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

through2-objectify

v0.1.1

Published

A through2 for transforming buffer (or string) streams into objectMode ones (or vice-versa).

Downloads

258

Readme

#through2-objectify A through2 for transforming a buffer (or string) stream to an objectMode one (or vice-versa).

Build Status NPM

NPM

Usage

var objectify = require('through2-objectify')
  , concat = require('concat-stream')
  , net = require('net')

var srv = net.createServer(function(c) {
  c.end('abc')
}).listen(1337)

net.connect(1337).pipe(objectify(function(chunk, enc, cb) {
  var s = chunk.toString()
  for (var i = 0; i < s.length; i++) {
    this.push({ c: s[i] })
  }
  cb()
})).pipe(concat(function(values) {
  console.dir(values)
  /* Output:
    [
      { c: 'a' },
      { c: 'b' },
      { c: 'c' }
    ]
  */

  srv.close()
})

API

var objectify = require('through2-objectify')

objectify([options,] transformFn [, flushFn])

Create a through2 transform stream that converts buffers (or strings) to objects.

objectify.ctor([options,] transformFn [, flushFn])

Returns a constructor function for a custom stream that converts buffers (or strings) to objects. Useful if you want to have multiple streams with the same transform/flush functions, or if you want to inherit from the stream type.

objectify.deobj([options,] transformFn [, flushFn])

Create a through2 transform stream that converts objects to buffers (or strings).

objectify.deobjCtor([options,] transformFn [, flushFn])

Returns a constructor function for a custom stream that converts objects to buffers (or strings).

options

Any options valid for Transform streams can be passed, as well as the following objectify-specific options:

objectHighWaterMark

Sets the highWaterMark specifically for the object side of the stream (i.e. Readable on objectify, Writable on deobjectify). This allows you to control highWaterMarks separately and not buffer e.g. 16k objects when you want to buffer 16k bytes.

Defaults to 16.

transformFn

function(chunk, enc, cb)

Called for each buffer/string/object that needs to be transformed. See streams and through2 documentation for further details.

flushFn

function(cb)

Called just before emitting the end signal, but after all data has been transformed. See streams and through2 documentation for further details.

See also

Installation

npm install through2-objectify

Running tests

npm test

License

MIT