Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
802 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | /** Used as references for various `Number` constants. */
|
---|
| 2 | var MAX_SAFE_INTEGER = 9007199254740991;
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * Checks if `value` is a valid array-like length.
|
---|
| 6 | *
|
---|
| 7 | * **Note:** This method is loosely based on
|
---|
| 8 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
---|
| 9 | *
|
---|
| 10 | * @static
|
---|
| 11 | * @memberOf _
|
---|
| 12 | * @since 4.0.0
|
---|
| 13 | * @category Lang
|
---|
| 14 | * @param {*} value The value to check.
|
---|
| 15 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
---|
| 16 | * @example
|
---|
| 17 | *
|
---|
| 18 | * _.isLength(3);
|
---|
| 19 | * // => true
|
---|
| 20 | *
|
---|
| 21 | * _.isLength(Number.MIN_VALUE);
|
---|
| 22 | * // => false
|
---|
| 23 | *
|
---|
| 24 | * _.isLength(Infinity);
|
---|
| 25 | * // => false
|
---|
| 26 | *
|
---|
| 27 | * _.isLength('3');
|
---|
| 28 | * // => false
|
---|
| 29 | */
|
---|
| 30 | function isLength(value) {
|
---|
| 31 | return typeof value == 'number' &&
|
---|
| 32 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | module.exports = isLength;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.