root / HServer / 00.Server / 00.Program / node_modules / lodash / toLength.js
이력 | 보기 | 이력해설 | 다운로드 (868 Bytes)
1 | 39 | HKM | 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; |