UNPKG

resolve-package-path

Version:

a special purpose fast memoizing way to resolve a node modules package.json

32 lines 818 B
'use strict'; function makeCache() { // object with no prototype const cache = Object.create(null); // force the jit to immediately realize this object is a dictionary. This // should prevent the JIT from going wastefully one direction (fast mode) // then going another (dict mode) after cache['_cache'] = 1; delete cache['_cache']; return cache; } module.exports = class Cache { constructor() { this._store = makeCache(); } set(key, value) { return (this._store[key] = value); } get(key) { return this._store[key]; } has(key) { return key in this._store; } delete(key) { delete this._store[key]; } get size() { return Object.keys(this._store).length; } }; //# sourceMappingURL=cache.js.map