Move internal modules to “internal” folder.

This commit is contained in:
John-David Dalton
2017-01-10 00:44:25 -08:00
parent 2b05673125
commit 26ea38dcf4
500 changed files with 726 additions and 726 deletions

33
.internal/createRound.js Normal file
View File

@@ -0,0 +1,33 @@
import toInteger from './toInteger.js';
import toNumber from './toNumber.js';
import toString from './toString.js';
/* Built-in method references for those with the same name as other `lodash` methods. */
const nativeMin = Math.min;
/**
* Creates a function like `round`.
*
* @private
* @param {string} methodName The name of the `Math` method to use when rounding.
* @returns {Function} Returns the new round function.
*/
function createRound(methodName) {
const func = Math[methodName];
return (number, precision) => {
number = toNumber(number);
precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
if (precision) {
// Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details.
let pair = `${ toString(number) }e`.split('e');
const value = func(`${ pair[0] }e${ +pair[1] + precision }`);
pair = `${ toString(value) }e`.split('e');
return +`${ pair[0] }e${ +pair[1] - precision }`;
}
return func(number);
};
}
export default createRound;