node-ejs-renderer/node_modules/thingies/es2020/LruMap.js
2024-06-09 13:55:01 -04:00

25 lines
609 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LruMap = void 0;
class LruMap extends Map {
constructor(limit = Infinity) {
super();
this.limit = limit;
}
set(key, value) {
super.set(key, value);
if (this.size > this.limit)
this.delete(super.keys().next().value);
return this;
}
get(key) {
if (!super.has(key))
return undefined;
const value = super.get(key);
super.delete(key);
super.set(key, value);
return value;
}
}
exports.LruMap = LruMap;