Expose _.toLength.

This commit is contained in:
Xotic750
2015-10-30 21:04:17 +01:00
committed by John-David Dalton
parent c7ef030ef5
commit 2b4a10c159
2 changed files with 44 additions and 4 deletions

View File

@@ -1475,9 +1475,9 @@
* `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`, `runInContext`,
* `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`,
* `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `sum`,
* `sumBy`, `template`, `toLower`, `toInteger`, `toSafeInteger`, `toString`,
* `toUpper`, `trim`, `trimLeft`, `trimRight`, `truncate`, `unescape`, `uniqueId`,
* `upperCase`, `upperFirst`, `value`, and `words`
* `sumBy`, `template`, `toLower`, `toInteger`, `toLength`, `toSafeInteger`,
* `toString`, `toUpper`, `trim`, `trimLeft`, `trimRight`, `truncate`, `unescape`,
* `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words`
*
* @name _
* @constructor
@@ -9832,6 +9832,22 @@
return value === value ? (remainder ? value - remainder : value) : 0;
}
/**
* The abstract operation toLength converts its argument to an integer
* suitable for use as the length of an array-like object.
*
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The object to be converted to a length.
* @return {number} Integer in range 0 to 2^32-1.
*/
function toLength(value) {
return clamp(toInteger(value), 0, MAX_ARRAY_LENGTH);
}
/**
* Converts `value` to a plain object flattening inherited enumerable
* properties of `value` to own properties of the plain object.
@@ -13487,6 +13503,7 @@
lodash.sumBy = sumBy;
lodash.template = template;
lodash.toInteger = toInteger;
lodash.toLength = toLength;
lodash.toLower = toLower;
lodash.toSafeInteger = toSafeInteger;
lodash.toString = toString;