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:
+1
-1
@@ -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",
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user