Files
NapCatQQ/.pnpm-store/v3/files/d8/3a7859dde1501a5a0fe3f87c2547e35ae905f8d7eb16f16e864cd3bf97b39d37d9e6d34b896bbe310e297a87219bb5eb281b19f483d542a38ee253f8c5c7c1
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

116 lines
2.6 KiB
Plaintext

/**
* A collection of shims that provide minimal functionality of the ES6 collections.
*
* These implementations are not meant to be used outside of the ResizeObserver
* modules as they cover only a limited range of use cases.
*/
/* eslint-disable require-jsdoc, valid-jsdoc */
const MapShim = (() => {
if (typeof Map !== 'undefined') {
return Map;
}
/**
* Returns index in provided array that matches the specified key.
*
* @param {Array<Array>} arr
* @param {*} key
* @returns {number}
*/
function getIndex(arr, key) {
let result = -1;
arr.some((entry, index) => {
if (entry[0] === key) {
result = index;
return true;
}
return false;
});
return result;
}
return class {
constructor() {
this.__entries__ = [];
}
/**
* @returns {boolean}
*/
get size() {
return this.__entries__.length;
}
/**
* @param {*} key
* @returns {*}
*/
get(key) {
const index = getIndex(this.__entries__, key);
const entry = this.__entries__[index];
return entry && entry[1];
}
/**
* @param {*} key
* @param {*} value
* @returns {void}
*/
set(key, value) {
const index = getIndex(this.__entries__, key);
if (~index) {
this.__entries__[index][1] = value;
} else {
this.__entries__.push([key, value]);
}
}
/**
* @param {*} key
* @returns {void}
*/
delete(key) {
const entries = this.__entries__;
const index = getIndex(entries, key);
if (~index) {
entries.splice(index, 1);
}
}
/**
* @param {*} key
* @returns {void}
*/
has(key) {
return !!~getIndex(this.__entries__, key);
}
/**
* @returns {void}
*/
clear() {
this.__entries__.splice(0);
}
/**
* @param {Function} callback
* @param {*} [ctx=null]
* @returns {void}
*/
forEach(callback, ctx = null) {
for (const entry of this.__entries__) {
callback.call(ctx, entry[1], entry[0]);
}
}
};
})();
export {MapShim as Map};