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

reiterate

v0.0.0

Published

Construct JSON object trees recursively, asynchronously to join data from multiple data sources.

Downloads

6

Readme

Reitrate

Evented construction of JSON objects.

Synopsis

Reiterate creates a JSON object tree asynchronously, interpreting functions in the object heirarchy as data methods that accept a callback.

You can use functions to define the functions that populate the structure.

The data functions can inject more data functions into the heirarchy, so that the children can be created based on their parents.

var loadObject = require('reiterate').loadObject,
    datastore = require('acme-datastore').datastore;

function getArticleByPerson(personId) {
  function (callback) {
    datastore.select('articles', 'personId', personId, callback);
  }
}

function getPerson (id) {
  function (callback) {
    datastore.select('people', id, function (error, people) {
      if (error) {
        callback(error);
      }  else {
        person = people.shift();
        person.articles = getArticleByPerson(person.id);
        callback(null, person);
      }
    });
  }
}

var data = { person: getPeople(1) };
loadObject(data, function (error, data) {
  for (var i = 0; i < data.person.articles.length; i++) {
    article = data.person.articles[i];
    process.stdout.write(article.title + ' by ' + person.name + '\n');
  }
});

For those of you using a NoSQL database, this is an easy way to get a pseudo-JOIN, to create a psuedo-JOIN across database engines

API

require('reiterate')

The reiterate module exports the loadObject method.

var loadObject = require('async-object').loadObject;

loadObject(object, callback)

  • object — The object to populate.
  • callback — The callback to invoke when the object has been loaded, or when an error occurs.

Use the loadObject method to load the object and invoke the given callback when the object is loaded or if there is an error.

Any valid JSON type can be passed to loadObject. If the type is not an object, array or function, the data is simply forwarded to the callback.

loadObject will descend the object contents recursively. Any values of type function found in an object or array are assumed to be methods that accept a single callback and invoked. The callback is of the form callback(error, data).

If data generation function invokes the callback is invoked with an error, the error is forwarded to the user callback passed to loadObject and loading ends. Otherwise, each value in th data passed to the callback descended searching for functions.

Note that each value of the data given to the is first checked for a function that needs to be expanded, invokes the function if it exists. This means that a one data function can return a data structure with data functions in it, and those data functions will be be expanded before they are assigned to the tree.

You can also pass a function as the object argument so that the expanded data callback result is given to the user callback.

Change Log

Changes for each release.

Version 0.0.0

Released: Mon Jul 23 02:29:04 UTC 2012

  • Build on Travis CI. #4.
  • Rename to reiterate. #2.