lodash.round
Advanced tools
Comparing version 3.10.0 to 3.10.1
279
index.js
/** | ||
* lodash 3.10.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* lodash 3.10.1 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
/** Native method references. */ | ||
var pow = Math.pow; | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY = 1 / 0, | ||
MAX_INTEGER = 1.7976931348623157e+308, | ||
NAN = 0 / 0; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
symbolTag = '[object Symbol]'; | ||
/** Used to match leading and trailing whitespace. */ | ||
var reTrim = /^\s+|\s+$/g; | ||
/** Used to detect bad signed hexadecimal string values. */ | ||
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; | ||
/** Used to detect binary string values. */ | ||
var reIsBinary = /^0b[01]+$/i; | ||
/** Used to detect octal string values. */ | ||
var reIsOctal = /^0o[0-7]+$/i; | ||
/** Built-in method references without a dependency on `global`. */ | ||
var freeParseInt = parseInt; | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** | ||
* Creates a `_.ceil`, `_.floor`, or `_.round` function. | ||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/** Built-in value references. */ | ||
var _Symbol = global.Symbol; | ||
/** Used to convert symbols to primitives and strings. */ | ||
var symbolProto = _Symbol ? _Symbol.prototype : undefined, | ||
symbolToString = _Symbol ? symbolProto.toString : undefined; | ||
/** | ||
* Creates a function like `_.round`. | ||
* | ||
@@ -23,6 +61,12 @@ * @private | ||
return function(number, precision) { | ||
precision = precision === undefined ? 0 : (+precision || 0); | ||
number = toNumber(number); | ||
precision = toInteger(precision); | ||
if (precision) { | ||
precision = pow(10, precision); | ||
return func(number * precision) / precision; | ||
// Shift with exponential notation to avoid floating-point issues. | ||
// See [MDN](https://mdn.io/round#Examples) for more details. | ||
var pair = (toString(number) + 'e').split('e'), | ||
value = func(pair[0] + 'e' + (+pair[1] + precision)); | ||
pair = (toString(value) + 'e').split('e'); | ||
return +(pair[0] + 'e' + (+pair[1] - precision)); | ||
} | ||
@@ -34,8 +78,219 @@ return func(number); | ||
/** | ||
* Calculates `n` rounded to `precision`. | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array constructors, and | ||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. | ||
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
// Avoid a V8 JIT bug in Chrome 19-20. | ||
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details. | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function isSymbol(value) { | ||
return typeof value == 'symbol' || | ||
(isObjectLike(value) && objectToString.call(value) == symbolTag); | ||
} | ||
/** | ||
* Converts `value` to an integer. | ||
* | ||
* **Note:** This function is loosely 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); | ||
* // => 3 | ||
* | ||
* _.toInteger(Number.MIN_VALUE); | ||
* // => 0 | ||
* | ||
* _.toInteger(Infinity); | ||
* // => 1.7976931348623157e+308 | ||
* | ||
* _.toInteger('3'); | ||
* // => 3 | ||
*/ | ||
function toInteger(value) { | ||
if (!value) { | ||
return value === 0 ? value : 0; | ||
} | ||
value = toNumber(value); | ||
if (value === INFINITY || value === -INFINITY) { | ||
var sign = (value < 0 ? -1 : 1); | ||
return sign * MAX_INTEGER; | ||
} | ||
var remainder = value % 1; | ||
return value === value ? (remainder ? value - remainder : value) : 0; | ||
} | ||
/** | ||
* Converts `value` to a number. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {number} Returns the number. | ||
* @example | ||
* | ||
* _.toNumber(3); | ||
* // => 3 | ||
* | ||
* _.toNumber(Number.MIN_VALUE); | ||
* // => 5e-324 | ||
* | ||
* _.toNumber(Infinity); | ||
* // => Infinity | ||
* | ||
* _.toNumber('3'); | ||
* // => 3 | ||
*/ | ||
function toNumber(value) { | ||
if (isObject(value)) { | ||
var other = isFunction(value.valueOf) ? value.valueOf() : value; | ||
value = isObject(other) ? (other + '') : other; | ||
} | ||
if (typeof value != 'string') { | ||
return value === 0 ? value : +value; | ||
} | ||
value = value.replace(reTrim, ''); | ||
var isBinary = reIsBinary.test(value); | ||
return (isBinary || reIsOctal.test(value)) | ||
? freeParseInt(value.slice(2), isBinary ? 2 : 8) | ||
: (reIsBadHex.test(value) ? NAN : +value); | ||
} | ||
/** | ||
* Converts `value` to a string if it's not one. An empty string is returned | ||
* for `null` and `undefined` values. The sign of `-0` is preserved. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {string} Returns the string. | ||
* @example | ||
* | ||
* _.toString(null); | ||
* // => '' | ||
* | ||
* _.toString(-0); | ||
* // => '-0' | ||
* | ||
* _.toString([1, 2, 3]); | ||
* // => '1,2,3' | ||
*/ | ||
function toString(value) { | ||
// Exit early for strings to avoid a performance hit in some environments. | ||
if (typeof value == 'string') { | ||
return value; | ||
} | ||
if (value == null) { | ||
return ''; | ||
} | ||
if (isSymbol(value)) { | ||
return _Symbol ? symbolToString.call(value) : ''; | ||
} | ||
var result = (value + ''); | ||
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; | ||
} | ||
/** | ||
* Computes `number` rounded to `precision`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Math | ||
* @param {number} n The number to round. | ||
* @param {number} number The number to round. | ||
* @param {number} [precision=0] The precision to round to. | ||
@@ -42,0 +297,0 @@ * @returns {number} Returns the rounded number. |
{ | ||
"name": "lodash.round", | ||
"version": "3.10.0", | ||
"description": "The modern build of lodash’s `_.round` as a module.", | ||
"version": "3.10.1", | ||
"description": "The lodash method `_.round` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
"icon": "https://lodash.com/icon.svg", | ||
"license": "MIT", | ||
"keywords": "lodash, lodash-modularized, stdlib, util", | ||
"keywords": "lodash, lodash-modularized, stdlib, util, round", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)", | ||
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
@@ -16,0 +14,0 @@ ], |
@@ -1,4 +0,4 @@ | ||
# lodash.round v3.10.0 | ||
# lodash.round v3.10.1 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.round` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.round` exported as a [Node.js](https://nodejs.org/) module. | ||
@@ -8,3 +8,2 @@ ## Installation | ||
Using npm: | ||
```bash | ||
@@ -15,4 +14,3 @@ $ {sudo -H} npm i -g npm | ||
In Node.js/io.js: | ||
In Node.js: | ||
```js | ||
@@ -22,2 +20,2 @@ var round = require('lodash.round'); | ||
See the [documentation](https://lodash.com/docs#round) or [package source](https://github.com/lodash/lodash/blob/3.10.0-npm-packages/lodash.round) for more details. | ||
See the [documentation](https://lodash.com/docs#round) or [package source](https://github.com/lodash/lodash/blob/3.10.1-npm-packages/lodash.round) for more details. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10278
287
19
1