
Security News
OpenGrep Restores Fingerprinting in JSON and SARIF Outputs
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
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.
The module is released in the public npm registry and can be installed by running:
npm install --save truth
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:
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:
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.
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);
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
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
The internal dataset has changed, fetch data from merged data stores, re-apply
all data transformations and trigger the change
event.
truth.change();
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:
undo
method.truth.transform('map', function (row) {
return {
foo: row.value
};
});
truth.add({ value: 'awesome' });
truth.get(); // [ { foo: 'awesome' }]
Undo a transformation on the dataset. This method requires 2 arguments:
transform
method.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.
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();
MIT
FAQs
The only data store that tells the truth about your current state.
We found that truth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.