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

read-relaxed-json-from-stdin-pmb

v1.0.2

Published

Read and parse JSON objects from standard input. They may or may not be wrapped in an array. Hoard all the objects in RAM. Return a promise for an array of all those objects.

Downloads

16

Readme

read-relaxed-json-from-stdin-pmb

Read and parse JSON objects from standard input. They may or may not be wrapped in an array. Hoard all the objects in RAM. Return a promise for an array of all those objects.

Squandering RAM like crazy.

In the project this was born from, RAM usage has not been a concern yet. Thus, it's currently implemented quick-and-dirty.

Prepare for a temporary RAM spike of 10 times your input data size and also a 100% load on one CPU core for (depending on input size) up to a few minutes.

In addition to hoarding all the objects, the wrapper array detection is implemented naively and not very robust. It's meant as a mere convenience:

  • If the first line has a [ or { and in front of that has something that looks like an export mechanism, the export mechanism is discarded.
  • In the last line, any trailing ) and/or ; are discarded.
  • If data doesn't start with [, all of it is wrapped in […].
  • Any inverse pair of } and { that has a newline between them, is assumed to be an object border and thus a comma is inserted.
  • This happens with several steps of RegExps replacements on a string representation of the entire input, putting garbage collection to the test.
  • If the final record read is null, it's discarded instead. This is a convenience to help your input source produce a valid JSON array without having to care about whether to print a comma after each record: It can just always print the comma, and then print null] later.

API

This module exports one function:

readRelaxedJsonFromStdin(opt)

opt is an optional options object that supports these optional keys:

  • logFunc (default = false): Discard progress messages. Otherwise, a function to call for informational progress messages. Will be called with the template string as first argument, and for messages that contain %s placeholders, additional values that go into those slots. Thus, API is compatible with console.info and its siblings.
  • offset (default = 0), limit (default = 0), defaultLimit (default = 0):
    • All of them, if set, are expected to be non-negative integer numbers.
    • If any of them is truthy (expectation: a positive number), the input array is .slice()d for your API convenience. This happens as an extra step after reading and decoding, so it increases RAM and CPU usage rather than saving any.
    • offset is how many records are discarded from the start of the array.
    • If limit is 0, defaultLimit is used instead.
    • limit (or defaultLimit), if truthy, denotes the maximum number of records to return. 0 means unlimited.

Known issues

  • Needs more/better tests and docs.

 

License

MIT