2025-10-28 02:51:50 +08:00
|
|
|
import { createMethodShim } from "./shared.js";
|
|
|
|
|
|
2022-09-18 17:50:14 +08:00
|
|
|
/*
|
|
|
|
|
Note:
|
|
|
|
|
|
|
|
|
|
1. `acorn` contains `RegExpValidationState` class with `.at` method (2 arguments)
|
|
|
|
|
2. `postcss` contains `Container` class with `.at` method
|
|
|
|
|
*/
|
|
|
|
|
|
2025-10-28 02:51:50 +08:00
|
|
|
function stringOrArrayAt(index) {
|
|
|
|
|
return this[index < 0 ? this.length + index : index];
|
|
|
|
|
}
|
2022-09-26 22:54:17 +08:00
|
|
|
|
2026-01-10 15:07:34 +08:00
|
|
|
const at = /* @__PURE__ */ createMethodShim("at", function () {
|
2023-03-26 04:14:48 +09:00
|
|
|
// "relative indexing" is not available in Node.js v14
|
|
|
|
|
// `.at` method is slower than property access on Node.js v16 and v18, see #14396
|
|
|
|
|
// Only checked arrays and strings, since we haven't use `TypedArray`, and the transform only works for sources
|
2025-10-28 02:51:50 +08:00
|
|
|
if (Array.isArray(this) || typeof this === "string") {
|
|
|
|
|
return stringOrArrayAt;
|
2023-03-26 04:14:48 +09:00
|
|
|
}
|
2025-10-28 02:51:50 +08:00
|
|
|
});
|
2022-09-18 17:50:14 +08:00
|
|
|
|
|
|
|
|
export default at;
|