fix: 修复低版本浏览器不兼容 (#301)

* feat: add polyfills for Array.prototype.at and String.prototype.at methods

* chore: bump version to v0.9.51
This commit is contained in:
haorwen
2026-01-18 08:42:27 +08:00
committed by GitHub
parent dfe6a7e193
commit 87f0992ae5
2 changed files with 24 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vocechat-web",
"version": "0.9.50",
"version": "0.9.51",
"homepage": "https://voce.chat",
"dependencies": {
"@metamask/onboarding": "^1.0.1",
+23
View File
@@ -18,3 +18,26 @@ if (!isSupported) {
}
// hasown API
"hasOwn" in Object || (Object.hasOwn = Object.call.bind(Object.hasOwnProperty));
// Array.prototype.at() and String.prototype.at() polyfill
if (!Array.prototype.at) {
Array.prototype.at = function (index) {
const len = this.length;
const relativeIndex = index >= 0 ? index : len + index;
if (relativeIndex < 0 || relativeIndex >= len) {
return undefined;
}
return this[relativeIndex];
};
}
if (!String.prototype.at) {
String.prototype.at = function (index) {
const len = this.length;
const relativeIndex = index >= 0 ? index : len + index;
if (relativeIndex < 0 || relativeIndex >= len) {
return undefined;
}
return this[relativeIndex];
};
}