Expose _.toInteger.

This commit is contained in:
John-David Dalton
2015-09-04 08:35:36 -07:00
parent b534b83756
commit e516d99b2d
2 changed files with 29 additions and 13 deletions

View File

@@ -4384,17 +4384,6 @@
return typeof value == 'function' ? value : identity;
}
/**
* Converts `value` to an integer.
*
* @private
* @param {*} value The value to convert.
* @returns {number} Returns the integer.
*/
function toInteger(value) {
return nativeFloor(value) || 0;
}
/**
* Creates a clone of `wrapper`.
*
@@ -8863,6 +8852,31 @@
return func(value);
}
/**
* Converts `value` to an integer.
*
* **Note:** This function is based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to convert.
* @returns {number} Returns the converted integer.
* @example
*
* _.toInteger('3.14');
* // => 3
*
* _.toInteger(NaN);
* // => 0
*
* _.toInteger(Infinity);
* // => Infinity
*/
function toInteger(value) {
return nativeFloor(value) || 0;
}
/**
* Converts `value` to a plain object flattening inherited enumerable
* properties of `value` to own properties of the plain object.
@@ -11949,6 +11963,7 @@
lodash.sum = sum;
lodash.sumBy = sumBy;
lodash.template = template;
lodash.toInteger = toInteger;
lodash.trim = trim;
lodash.trimLeft = trimLeft;
lodash.trimRight = trimRight;

View File

@@ -17387,7 +17387,8 @@
'random',
'reduce',
'reduceRight',
'some'
'some',
'toInteger'
];
_.each(funcs, function(methodName) {
@@ -17596,7 +17597,7 @@
var acceptFalsey = _.difference(allMethods, rejectFalsey);
test('should accept falsey arguments', 232, function() {
test('should accept falsey arguments', 233, function() {
var emptyArrays = _.map(falsey, _.constant([]));
_.each(acceptFalsey, function(methodName) {