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

/node_modules/lodash/toSafeInteger.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 37 lines | 9 code | 3 blank | 25 comment | 0 complexity | 5ec55825f8af31cda1008dab9ec48a47 MD5 | raw file
 1var baseClamp = require('./_baseClamp'),
 2    toInteger = require('./toInteger');
 3
 4/** Used as references for various `Number` constants. */
 5var MAX_SAFE_INTEGER = 9007199254740991;
 6
 7/**
 8 * Converts `value` to a safe integer. A safe integer can be compared and
 9 * represented correctly.
10 *
11 * @static
12 * @memberOf _
13 * @since 4.0.0
14 * @category Lang
15 * @param {*} value The value to convert.
16 * @returns {number} Returns the converted integer.
17 * @example
18 *
19 * _.toSafeInteger(3.2);
20 * // => 3
21 *
22 * _.toSafeInteger(Number.MIN_VALUE);
23 * // => 0
24 *
25 * _.toSafeInteger(Infinity);
26 * // => 9007199254740991
27 *
28 * _.toSafeInteger('3.2');
29 * // => 3
30 */
31function toSafeInteger(value) {
32  return value
33    ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
34    : (value === 0 ? value : 0);
35}
36
37module.exports = toSafeInteger;