t-comm
Version:
专业、稳定、纯粹的工具库
27 lines (26 loc) • 821 B
TypeScript
/**
* Checks if `value` is a valid array-like index.
*
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
* @example
* ```ts
* isIndex(0); // true
* isIndex(1); // true
* isIndex(100); // true
* isIndex('0'); // true
* isIndex('999'); // true
* isIndex(-1); // false
* isIndex(1.5); // false
* isIndex('abc'); // false
* isIndex('01'); // false // 前导 0
* isIndex(5, 5); // false // value 必须 < length
* isIndex(4, 5); // true
* isIndex(0, 0); // false // length 为 0
* isIndex(Symbol('test')); // false
* isIndex(null); // false
* isIndex(undefined); // false
* ```
*/
export declare function isIndex(value: any, length?: number): boolean;