es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
21 lines (17 loc) • 520 B
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
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);
}
}
}
exports.isIndex = isIndex;