diff --git a/README.md b/README.md index 52f43c371..110261289 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash v4.11.0 +# lodash v4.11.1 The [lodash](https://lodash.com/) library exported as [npm packages](https://www.npmjs.com/browse/keyword/lodash-modularized) per method. diff --git a/lodash.nth/README.md b/lodash.nth/README.md index 9cea09be1..fa0e6cc9d 100644 --- a/lodash.nth/README.md +++ b/lodash.nth/README.md @@ -1,4 +1,4 @@ -# lodash.nth v4.11.0 +# lodash.nth v4.11.1 The [lodash](https://lodash.com/) method `_.nth` exported as a [Node.js](https://nodejs.org/) module. @@ -15,4 +15,4 @@ In Node.js: var nth = require('lodash.nth'); ``` -See the [documentation](https://lodash.com/docs#nth) or [package source](https://github.com/lodash/lodash/blob/4.11.0-npm-packages/lodash.nth) for more details. +See the [documentation](https://lodash.com/docs#nth) or [package source](https://github.com/lodash/lodash/blob/4.11.1-npm-packages/lodash.nth) for more details. diff --git a/lodash.nth/index.js b/lodash.nth/index.js index 1d0c7b67f..419ee8c2b 100644 --- a/lodash.nth/index.js +++ b/lodash.nth/index.js @@ -1,5 +1,5 @@ /** - * lodash 4.11.0 (Custom Build) + * lodash (Custom Build) * Build: `lodash modularize exports="npm" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -36,20 +36,6 @@ var reIsUint = /^(?:0|[1-9]\d*)$/; /** Built-in method references without a dependency on `root`. */ var freeParseInt = parseInt; -/** - * Checks if `value` is a valid array-like index. - * - * @private - * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ -function isIndex(value, length) { - value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; - length = length == null ? MAX_SAFE_INTEGER : length; - return value > -1 && value % 1 == 0 && value < length; -} - /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -61,7 +47,7 @@ var objectProto = Object.prototype; var objectToString = objectProto.toString; /** - * The base implementation of `_.nth` which doesn't coerce `n` to an integer. + * The base implementation of `_.nth` which doesn't coerce arguments. * * @private * @param {Array} array The array to query. @@ -78,8 +64,23 @@ function baseNth(array, n) { } /** - * Gets the nth element of `array`. If `n` is negative, the nth element - * from the end is returned. + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ +function isIndex(value, length) { + length = length == null ? MAX_SAFE_INTEGER : length; + return !!length && + (typeof value == 'number' || reIsUint.test(value)) && + (value > -1 && value % 1 == 0 && value < length); +} + +/** + * Gets the element at index `n` of `array`. If `n` is negative, the nth + * element from the end is returned. * * @static * @memberOf _ @@ -110,8 +111,7 @@ function nth(array, n) { * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); @@ -194,8 +194,7 @@ function isObjectLike(value) { * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * * _.isSymbol(Symbol.iterator); @@ -209,10 +208,45 @@ function isSymbol(value) { (isObjectLike(value) && objectToString.call(value) == symbolTag); } +/** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ +function toFinite(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; + } + return value === value ? value : 0; +} + /** * Converts `value` to an integer. * - * **Note:** This function is loosely based on + * **Note:** This method is loosely based on * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). * * @static @@ -223,7 +257,7 @@ function isSymbol(value) { * @returns {number} Returns the converted integer. * @example * - * _.toInteger(3); + * _.toInteger(3.2); * // => 3 * * _.toInteger(Number.MIN_VALUE); @@ -232,20 +266,14 @@ function isSymbol(value) { * _.toInteger(Infinity); * // => 1.7976931348623157e+308 * - * _.toInteger('3'); + * _.toInteger('3.2'); * // => 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; + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; } /** @@ -259,8 +287,8 @@ function toInteger(value) { * @returns {number} Returns the number. * @example * - * _.toNumber(3); - * // => 3 + * _.toNumber(3.2); + * // => 3.2 * * _.toNumber(Number.MIN_VALUE); * // => 5e-324 @@ -268,8 +296,8 @@ function toInteger(value) { * _.toNumber(Infinity); * // => Infinity * - * _.toNumber('3'); - * // => 3 + * _.toNumber('3.2'); + * // => 3.2 */ function toNumber(value) { if (typeof value == 'number') { diff --git a/lodash.nth/package.json b/lodash.nth/package.json index dd49bcfab..5fe4ac664 100644 --- a/lodash.nth/package.json +++ b/lodash.nth/package.json @@ -1,6 +1,6 @@ { "name": "lodash.nth", - "version": "4.11.0", + "version": "4.11.1", "description": "The lodash method `_.nth` exported as a module.", "homepage": "https://lodash.com/", "icon": "https://lodash.com/icon.svg",