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

stream-stringify

v2.3.3

Published

Stringify nested JSON through streams.

Downloads

68

Readme

Create streams for nested JSON structures of which you don't know about on beforehand.

Cheaper than JSON.stringify which always will buffers the entire object.

Example

jsonString = ''
root = sstringify().on('data', (data) -> jsonString += data)
root.writeKeyValue "firstKey", "firstValue"
nestedObject = root.startNewObject "nestedObject"
innerArray = nestedObject.startNewArray "innerArray"
innerArray.writeElement 1
innerArray.writeElement [2,3]
innerArray.stop()
nestedObject.writeKeyValue "anotherInnerKey", "anotherInnerValue"
nestedObject.stop()
root.stop()

jsonString is now:

{
  "firstKey": "firstValue",
  "nestedObject": {
    "innerArray": [
      1,
      [
        2,
        3
      ]
    ],
    "anotherInnerKey": "anotherInnerValue"
  }
}

Functionality

This stream supports functionality found in most streams, such as write(), end(), or destroy(). The methods described below are specific for this stream.

sstringify(options)

Constructs the root of the JSON structure. When specified, the following options change the behaviour of the stream:

  • type - String specifying the type of the stream root.
    • Object(Default) An object with key-value pairs
    • Array An array with arbitrary content
  • prettyFormat - Boolean specifying whether the object should be formatted beautifully.
  • tabWidth - If prettyFormat is true, then this is the number of spaces. Defaults to 2.
  • autoDestroy- Boolean specifying whether the object should be destroyed when ended. Default is true.

startNewObject(key)

Starts a new object stream which is connected to the specfied key. Returns the stream. When using an array, do not specify key.

startNewArray(key)

Starts a new array stream which is connected to the specfied key. Returns the stream. When using an array, do not specify key.

stop()

Notifies the stream that there won't be more information. This will close the bracket. The stream will automatically be ended and destroyed when not used by other streams (unless autoDestroy=false).

writeKeyValue(key,value)

Writes a key and a value to the stream. Does not work when working with an array.

writeElement(element)

Writes an element to the stream. Does not work when working with an object.

Set it off!

npm install stream-stringify