UNPKG

guilded.ts

Version:

A powerful NPM module that allows you to easily interact with the Guilded API.

45 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheCollection = void 0; const collection_1 = require("@discordjs/collection"); /** * A custom cache collection which has a max cache size. * @example new CacheCollection(); */ class CacheCollection extends collection_1.Collection { maxSize; /** * @param maxSize The max size of the cache. * @param entries The initial entries of the cache. */ constructor(maxSize, entries = []) { super(entries); this.maxSize = maxSize; if (maxSize && maxSize <= 1) throw new Error('Max cache size must be greater than 1.'); } /** * Set the max size of the cache. * @param maxSize The max size of the cache. * @returns The cache collection. * @example cache.setMaxSize(100); */ setMaxSize(maxSize) { this.maxSize = maxSize; return this; } /** * Set an entry in the cache. * @param key The key of the entry. * @param value The value of the entry. * @returns The cache collection. * @example cache.set(key, value); */ set(key, value) { if (this.maxSize && this.size >= this.maxSize) this.delete(this.firstKey()); return super.set(key, value); } } exports.CacheCollection = CacheCollection; //# sourceMappingURL=CacheCollection.js.map