who-set-it
v0.1.0
Published
Track where object properties are assigned
Downloads
6
Readme
who-set-it
Track where object properties are assigned. The primary use case is to track the location of global variable leaks.
Basic Usage
'use strict';
const WhoSetIt = require('who-set-it');
let target = { foo: 1 };
const proxy = WhoSetIt(target);
// Use the proxy in place of the original target.
target = proxy.proxy;
target.bar = 2;
// Revoke the proxy and restore the original target value.
target = proxy.revoke();
target.baz = 3;
// target is now { foo: 1, bar: 2, baz: 3 }
// proxy.locations contains information regarding 'bar'
// 'foo' and 'baz' are not in proxy.locations because the proxy was not active.
API
whoSetIt(obj)
- Arguments
obj
(object) - The object to act as the proxy target.
- Returns
- object - An object with the following schema.
proxy
(proxy) - A revocable Proxy whose target isobj
.locations
(array of objects) - An array containing information about property assignments toproxy
. Each object in the array has the following schema.property
(string) - The name of the property that was set.filename
(string) - The file where the assignment took place.line
(string) - The line infilename
where the assignment took place.column
(string) - The column infilename
where the assignment took place.
revoke()
(function) - A function that revokes the proxy and returnsobj
. This function has no effect on the proxy after the first call.
- object - An object with the following schema.
Creates a revocable proxy of the input object. The proxy can then be used in place of the original object. The set()
trap maintains an array of property assignments while the proxy is active. The original object can be restored by calling revoke()
.