unreal.js
Version:
A pak reader for games like VALORANT & Fortnite written in Node.JS
49 lines (48 loc) • 1.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnrealMap = void 0;
const collection_1 = __importDefault(require("@discordjs/collection"));
/**
* Map used in unreal.js
* This map uses <object>.equals() for looking up entries
* If the method doesn't exists, it falls back to: ===
* This can be useful if the key is not a primitive
* @extends {Collection}
*/
class UnrealMap extends collection_1.default {
/**
* Gets an entry
* @param {any} key Key to lookup
* @returns {V | undefined} Entry
*/
get(key) {
if (key.equals) {
return super.find((v, k) => k.equals(key));
}
else {
return super.get(key);
}
}
/**
* Deletes an entry
* @param {any} key Key of the entry to delete
* @returns {boolean} Whether the entry got deleted
*/
delete(key) {
if (key.equals) {
const backup = this;
this.clear();
backup
.filter((v, k) => !k.equals(key))
.forEach((v, k) => this.set(k, v));
return this.size !== backup.size;
}
else {
return super.delete(key);
}
}
}
exports.UnrealMap = UnrealMap;