UNPKG

filefive

Version:

SFTP/FTP/Amazon S3 client and dual-panel file manager for macOS and Linux

62 lines (61 loc) 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class default_1 { constructor() { this.entries = new Map; } set(key, value) { const found = this.entries.get(key); this.entries.set(key, found ? { count: ++found.count, value } : { count: 1, value }); return this; } has(key) { return this.entries.has(key); } get(key) { return this.entries.get(key)?.value; } inc(key) { const found = this.entries.get(key); return found ? ++found.count : 0; } dec(key) { const found = this.entries.get(key); if (found) { if (--found.count <= 0) { this.entries.delete(key); return found.value; } } return undefined; } del(key) { const found = this.entries.get(key); found && this.entries.delete(key); return found?.value; } count(key) { return this.entries.get(key)?.count; } modify(key, value) { const found = this.entries.get(key); if (found) { found.value = value; return true; } return false; } keys() { return this.entries.keys(); } renameKey(from, to) { if (!this.entries.has(from)) { return; } this.entries.has(to) ? this.entries.get(to).count += this.entries.get(from).count : this.entries.set(to, this.entries.get(from)); this.entries.delete(from); } } exports.default = default_1;