mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
Expose _.toInteger.
This commit is contained in:
37
lodash.js
37
lodash.js
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user