@haelp/teto
Version:
A typescript-based controllable TETR.IO client.
84 lines (83 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "polyfills", {
enumerable: true,
get: function() {
return polyfills;
}
});
(function(polyfills) {
class Map {
_entries = [];
constructor(iterable){
if (iterable) {
for (const [key, value] of iterable){
this.set(key, value);
}
}
}
get size() {
return this._entries.length;
}
set = (key, value)=>{
const index = this._entries.findIndex(([k])=>k === key);
if (index !== -1) {
this._entries[index][1] = value;
} else {
this._entries.push([
key,
value
]);
}
return this;
};
get = (key)=>{
const entry = this._entries.find(([k])=>k === key);
return entry ? entry[1] : undefined;
};
has = (key)=>{
return this._entries.some(([k])=>k === key);
};
delete = (key)=>{
const index = this._entries.findIndex(([k])=>k === key);
if (index !== -1) {
this._entries.splice(index, 1);
return true;
}
return false;
};
clear = ()=>{
this._entries = [];
};
forEach = (callback, thisArg)=>{
// Use a shallow copy to prevent issues if the map is modified during iteration
const entriesCopy = this._entries.slice();
for (const [key, value] of entriesCopy){
callback.call(thisArg, value, key, this);
}
};
*entries() {
for (const entry of this._entries){
yield entry;
}
}
*keys() {
for (const [key] of this._entries){
yield key;
}
}
*values() {
for (const [, value] of this._entries){
yield value;
}
}
[Symbol.iterator] = function*() {
yield* this.entries();
};
}
polyfills.Map = Map;
})(polyfills || (polyfills = {}));
var polyfills;
//# sourceMappingURL=index.js.map