15 lines
557 B
TypeScript
15 lines
557 B
TypeScript
/** 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];
|
|
},
|
|
});
|
|
}
|
|
}
|