main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
866 bytes
|
Line | |
---|
1 | import baseClamp from './_baseClamp.js';
|
---|
2 | import toInteger from './toInteger.js';
|
---|
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 | export default toLength;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.