LendAndRegret/node_modules/es-toolkit/dist/compat/_internal/isIndex.mjs
2026-05-02 17:27:43 +08:00

17 lines
424 B
JavaScript

const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
switch (typeof value) {
case 'number': {
return Number.isInteger(value) && value >= 0 && value < length;
}
case 'symbol': {
return false;
}
case 'string': {
return IS_UNSIGNED_INTEGER.test(value);
}
}
}
export { isIndex };