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

json-dam

v1.0.0

Published

Fill in a json stream with a dam of data!

Downloads

5

Readme

Json-dam

Fill in a stream of json, with a Dam of data!

Takes a stream of objects or ndjson, and creates a singular object out of it.

Its like getting the puzzle pieces, and putting it together into the finished puzzle!

Examples

Take a stream of ndjson and convert it to an object:

var jsonDam = require('json-dam')

ndjsonStream.pipe(jsonDam((error, thePuzzle) => {
  // Here we have the filled out puzzle content!
}))

Or pipe an object stream in like so to get an object out:

var jsonDam = require('json-dam')

objectStream.pipe(jsonDam({objectMode: true}, (error, thePuzzle) => {
  // Here we have the filled out puzzle content!
}))

API

  jsonDam(options, function callback (error, parsedObject) { })

Where:

  • options: an optional object that can take the following properties to configure the parser (all properties below default to false)

    • objectMode: A boolean that says if this will receive a stream of objects. Defaluts to false as by default it expects ndjson.
    • ignoreErrors: A boolean that says if this should ignore errorable inputs (a string by itself, etc.)
    • strictObjectMode: A boolean that says if this should return an error if two objects with the same key are passed in (excluding arrays)
    • strictArrayMode: A boolean that says if this should return an error if two objects with the same key are passed in (including arrays).
  • callback: A required function that takes the following params:

    • error: if there was an error parsing the inputs
    • parsedObject: the parsed object that was filled in by the parser

Notes

The stream isn't very smart, some things to keep in mind:

  • The most recently piped in properties are the ones output on the parsed object if strict mode is disabled. Example below...
  someStream.pipe({objectMode: true}, jsonDam((err, obj) => {
    // obj.foo === 'version2'
  }))
  someStream.write({foo: 'version1'})
  someStream.write({foo: 'version2'})
  • Piped in objects with properties that are arrays get combined, if strictArrayMode is disabled...
  someStream.pipe({objectMode: true}, jsonDam((err, obj) => {
    // obj.foo === 'version2'
  }))
  someStream.write({foo: 'version1'})
  someStream.write({foo: 'version2'})

I recommend checking out the tests to get a full understanding of the usage of this module.

Acknowlegements

Thanks to Matteo Collina for taking a look at this in the early stages.

Thanks to Rob Jefe Lindstaet for talking about the initial idea with me.

License

Copyright Glen Keane and other contributors, Licensed under MIT.