Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
868 bytes
|
Line | |
---|
1 | var baseClamp = require('./_baseClamp'),
|
---|
2 | toInteger = require('./toInteger');
|
---|
3 |
|
---|
4 | /** Used as references for the maximum length and index of an array. */
|
---|
5 | var MAX_ARRAY_LENGTH = 4294967295;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Converts `value` to an integer suitable for use as the length of an
|
---|
9 | * array-like object.
|
---|
10 | *
|
---|
11 | * **Note:** This method is based on
|
---|
12 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
---|
13 | *
|
---|
14 | * @static
|
---|
15 | * @memberOf _
|
---|
16 | * @since 4.0.0
|
---|
17 | * @category Lang
|
---|
18 | * @param {*} value The value to convert.
|
---|
19 | * @returns {number} Returns the converted integer.
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * _.toLength(3.2);
|
---|
23 | * // => 3
|
---|
24 | *
|
---|
25 | * _.toLength(Number.MIN_VALUE);
|
---|
26 | * // => 0
|
---|
27 | *
|
---|
28 | * _.toLength(Infinity);
|
---|
29 | * // => 4294967295
|
---|
30 | *
|
---|
31 | * _.toLength('3.2');
|
---|
32 | * // => 3
|
---|
33 | */
|
---|
34 | function toLength(value) {
|
---|
35 | return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
|
---|
36 | }
|
---|
37 |
|
---|
38 | module.exports = toLength;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.