Files
Sybil-2/web/src/lib/lite-compat.ts
T

15 lines
557 B
TypeScript
Raw Normal View History

/** Marked uses at() internally, including on Chromium-based readers predating it. */
export function installLiteCompatibility() {
if (!("at" in Array.prototype)) {
Object.defineProperty(Array.prototype, "at", {
configurable: true,
writable: true,
value: function at(this: unknown[], index: number) {
const offset = Math.trunc(Number(index)) || 0;
const position = offset < 0 ? this.length + offset : offset;
return position < 0 || position >= this.length ? undefined : this[position];
},
});
}
}