WeakValue

A Map with weakly referenced values, instead of keys, with an optional onValueCollected callback to pass aslong.
In Node.js, it requires V8 release v8.4 or greater.
import WeakValue from 'weak-value';
const wv = new WeakValue;
(() => {
const value = {};
wv.set('any-key', value, (key, map) => {
console.log(key, 'value collected');
console.log(map === wv);
});
})();
Please note that explicit wv.delete(key) will NOT invoke onValueCollected, as deleting a key does not mean its referenced value has been collected.