UNPKG

moltres-utils

Version:
52 lines (41 loc) 1.7 kB
"use strict"; require("core-js/modules/es6.object.define-property"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("core-js/modules/es7.symbol.async-iterator"); require("core-js/modules/es6.symbol"); var _constants = require("../constants"); function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } /** Used to detect unsigned integer values. */ var reIsUint = /^(?:0|[1-9]\d*)$/; /** * Checks if `value` is a valid array-like index. * * @function * @since v0.0.3 * @category lang * @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 * * isIndex(0) * //=> true * * isIndex(1) * //=> true * * isIndex(-1) * //=> false */ var isIndex = function isIndex(value) { var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _constants.MAX_SAFE_INTEGER; // NOTE BRN: max safe length is exactly MAX_SAFE_INTEGER since the length of an array cannot safely be greater than the max integer. var type = _typeof(value); return !!length && (type == 'number' || type != 'symbol' && reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length; }; var _default = isIndex; exports.default = _default; //# sourceMappingURL=isIndex.js.map