( iter: Collection<unknown, unknown>, index: number )
| 41 | } |
| 42 | |
| 43 | export function wrapIndex( |
| 44 | iter: Collection<unknown, unknown>, |
| 45 | index: number |
| 46 | ): number { |
| 47 | // This implements "is array index" which the ECMAString spec defines as: |
| 48 | // |
| 49 | // A String property name P is an array index if and only if |
| 50 | // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal |
| 51 | // to 2^32−1. |
| 52 | // |
| 53 | // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects |
| 54 | if (typeof index !== 'number') { |
| 55 | const uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32 |
| 56 | if ('' + uint32Index !== index || uint32Index === 4294967295) { |
| 57 | return NaN; |
| 58 | } |
| 59 | index = uint32Index; |
| 60 | } |
| 61 | return index < 0 ? ensureSize(iter) + index : index; |
| 62 | } |
| 63 | |
| 64 | export function returnTrue(): true { |
| 65 | return true; |
no test coverage detected