1.0.0 • Published 6 years ago
accessed v1.0.0
accessed
Accessed is a simple module that allows you to track property access of a given
object to ensure that only the data that is used (or not used) is included when
you JSON.stringify the data.
Install
The module is published in the public npm registry and can be installed by running:
npm install --save accessedUsage
const accessed = require('accessed');
const data = accessed({
foo: 'bar',
bar: 'wat',
key: 'value'
});
console.log(data.foo);
console.log(JSON.stringify(data)); // {"foo":"bar"}
console.log(data.bar);
console.log(JSON.stringify(data)); // {"foo":"bar", "bar": "wat"}The module exposes the accessed function as default export. The function
accepts 2 arguments.
dataThe object that needs to be tracked.optionsAdditional configurationkeysAn array of keys that should be included, even when they are not accessed by the code.excludeInstead of returning an object onJSON.stringifythat represents the keys that were accessed, return the data that was not accesed.
const data = accessed({ foo: 'bar', hello: 'world' }, {
keys: ['hello']
});
console.log(JSON.stringify(data)); // {"hello":"world"}License
1.0.0
6 years ago