HACCESSED
Snoop on your objects and see what they're up to

About
Haccessed is a function that "hijacks" an object, clones it, and exposes a "hidden" __print__
method. This __print__
method will return the original object filtering out un-accessed properties. It does this by using the Object.defineProperty
method, which keeps the original object intact whilst monitoring lookups on properties.
Compatibility
This module is wrapped in UMD, and will work in any JavaScript environment that supports ES5 features.
You can:
- Bundle it in your
webpack
build. require
it in node.- Use it in
rewire
or jest.mock
. require
it AMD style for requirejs
.
Use Cases
- Validate which fields of an API are being actively used.
- Inject into a test to validate lookups.
- Verify that fields aren't being used after a deprecation.
- Ensure pseudo-private
_hidden
fields aren't getting called.
Simple Example
const haccessed = require('haccessed');
const myObject = { id: 123, name: 'joel' };
const hijacked = haccessed(myObject);
hijacked.id;
hijacked.__print__();
Complex Example
const haccessed = require('haccessed');
const myObject = {
id: 1,
name: 'joel',
address: {
zip: '55555',
state: 'wa'
},
friends: [{
id: 2,
name: 'bob'
}, {
id: 3,
name: 'jane'
} , {
id: 4,
name: 'sue'
}]
};
const hijacked = haccessed(myObject);
hijacked.id;
hijacked.address.state;
hijacked.friends[0].name;
hijacked.__print__();
TODO