PageRenderTime 25ms CodeModel.GetById 19ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/toInteger.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 36 lines | 7 code | 3 blank | 26 comment | 0 complexity | e77fa1f31dbef0152e12736928ac4918 MD5 | raw file
 1var toFinite = require('./toFinite');
 2
 3/**
 4 * Converts `value` to an integer.
 5 *
 6 * **Note:** This method is loosely based on
 7 * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
 8 *
 9 * @static
10 * @memberOf _
11 * @since 4.0.0
12 * @category Lang
13 * @param {*} value The value to convert.
14 * @returns {number} Returns the converted integer.
15 * @example
16 *
17 * _.toInteger(3.2);
18 * // => 3
19 *
20 * _.toInteger(Number.MIN_VALUE);
21 * // => 0
22 *
23 * _.toInteger(Infinity);
24 * // => 1.7976931348623157e+308
25 *
26 * _.toInteger('3.2');
27 * // => 3
28 */
29function toInteger(value) {
30  var result = toFinite(value),
31      remainder = result % 1;
32
33  return result === result ? (remainder ? result - remainder : result) : 0;
34}
35
36module.exports = toInteger;