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 🙏

© 2026 – Pkg Stats / Ryan Hefner

truth

v2.1.2

Published

The only data store that tells the truth about your current state.

Readme

truth

Version npmBuild StatusDependenciesCoverage Status

Truth allows you to merge different sets of data in to one single source of truth. The data can be manipulated from one central point in your application leading to a better separation of concerns and maintainability of the project.

Changes propagate through all the merged data sets so you know when your data set has changed.

Installation

The module is released in the public npm registry and can be installed by running:

npm install --save truth

Usage

First of all we need to require the module and create a new Truth instance as shown in the example code blow. This is the bare minimum required bootstrapping code.

'use strict';

var Truth = require('truth')
  , truth = new Truth();

While it's certainly possible to create truth instances without any arguments, there are a couple of arguments that can be set:

  1. The first argument can be a string with the name of the store. This will be used when merging stores and can be useful for debugging purposes.
  2. Configuration object where you can set:
  • key The name of the key that should be used to determine duplicates when merging truth instances.

Now that we've constructed our first truth instance we can look at the various of API methods that are available:

truth.add

Add a new row(s) in to the data set. You can supply as many arguments as you wish as they will all been seen as new rows that should be inserted. Once the insertion has occurred a change event will be triggered. So if you have multiple rows, it makes more sense to supply all at once as arguments instead of doing multiple invocations to truth.add().

truth.add({ another: 'row' }, { more: 'rows'i });

There is some small level of duplication detection where it tries to find exactly the same item in the current data set. So the method only trigger's changes when something is actually inserted.

truth.remove

Remove one or more rows from the data set. Please note that this only removes rows who equals those that got added before any modifications.

var row = { foo: 'bar' };

truth.add(row);
truth.remove(row);

truth.has

Test if a certain key->value combination is present in the data store. The first argument is the key of the row you're searching for and the second argument is an optional value to test against.

truth.add({ foo: 'bar' });

truth.has('foo', 'bar'); // true
truth.has('foo', 'baz'); // false

truth.find

Find a row in the dataset. Searches are done based on key/value matching.

var row = { foo: 'bar' }
  , found;

truth.add(row);
found = truth.find('foo', 'bar');

console.log(row === found); // true

truth.change

The internal dataset has changed, fetch data from merged data stores, re-apply all data transformations and trigger the change event.

truth.change();

truth.transform

Add additional data transformation methods, these should be existing methods on an Array, so you can use things like map, reduce, sort and what not. There are 3 requirement arguments:

  • The method name as string.
  • The actual function that does the transformation. If you supply a reduce method please assume that no default reduce value is given so you should return that on the first call.
  • Name of the transform method. This allows easy removal of transformations using the undo method.
truth.transform('map', function (row) {
  return {
    foo: row.value
  };
});

truth.add({ value: 'awesome' });
truth.get(); // [ { foo: 'awesome' }]

truth.undo

Undo a transformation on the dataset. This method requires 2 arguments:

  • The method name as string.
  • The name that you supplied as third argument in the transform method.

truth.merge

Merge the data from another truth store, the merging can be done based on a key to prevent duplicate rows. The primary data store will always be preferred over the merged data store.

When a merged truth store changes it data, it will also trigger a change event for your data store so they are always in sync.

var another = new Truth();

truth.add({ foo: 'bar', hello: 'world' });
another.add({ foo: 'bar', hello: 'hi' }, { foo: 'baz', hello: 'hi' });

truth.merge(another, 'foo');

In the example above we're merging our primary truth store another truth store. We supply the de-duplication key as second argument. So when we truth.get() data from the primary store it will have:

[
  { foo: 'bar', hello: 'world' },
  { foo: 'baz', hello: 'hi' }
]

As rows.

truth.destroy

Completely destroy the truth instance. No more methods should be called after this method is called so it can be safely collected by garbage collectors. When it's destroyed, it will emit an destroy method.

truth.destroy();

License

MIT