UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

37 lines (30 loc) 1.11 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _typeof = require('@babel/runtime/helpers/typeof'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); /** * Used as references for various `Number` constants. * @private */ var MAX_SAFE_INTEGER = 9007199254740991; /** * Used to detect unsigned integer values. * @private */ var reIsUint = /^(?:0|[1-9]\d*)$/; /** * 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`. */ function isIndex(value, length) { if (length === void 0) { length = MAX_SAFE_INTEGER; } var type = _typeof__default["default"](value); return !!length && (type == 'number' || type != 'symbol' && reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length; } exports.isIndex = isIndex;