summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/lodash/internal/isIndex.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/lodash/internal/isIndex.js')
-rw-r--r--deps/npm/node_modules/lodash/internal/isIndex.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/deps/npm/node_modules/lodash/internal/isIndex.js b/deps/npm/node_modules/lodash/internal/isIndex.js
new file mode 100644
index 0000000000..469164bfde
--- /dev/null
+++ b/deps/npm/node_modules/lodash/internal/isIndex.js
@@ -0,0 +1,24 @@
+/** Used to detect unsigned integer values. */
+var reIsUint = /^\d+$/;
+
+/**
+ * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
+ * of an array-like value.
+ */
+var MAX_SAFE_INTEGER = 9007199254740991;
+
+/**
+ * Checks if `value` is a valid array-like index.
+ *
+ * @private
+ * @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) {
+ value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
+ length = length == null ? MAX_SAFE_INTEGER : length;
+ return value > -1 && value % 1 == 0 && value < length;
+}
+
+module.exports = isIndex;