lodash.size
Advanced tools
Comparing version 3.0.2 to 4.0.0
279
index.js
/** | ||
* lodash 3.0.2 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* lodash 4.0.0 (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> | ||
@@ -11,9 +11,64 @@ */ | ||
/** Used as references for various `Number` constants. */ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
stringTag = '[object String]'; | ||
/** Used to compose unicode character classes. */ | ||
var rsAstralRange = '\\ud800-\\udfff', | ||
rsComboRange = '\\u0300-\\u036f\\ufe20-\\ufe23', | ||
rsVarRange = '\\ufe0e\\ufe0f'; | ||
/** Used to compose unicode capture groups. */ | ||
var rsAstral = '[' + rsAstralRange + ']', | ||
rsCombo = '[' + rsComboRange + ']', | ||
rsModifier = '(?:\\ud83c[\\udffb-\\udfff])', | ||
rsNonAstral = '[^' + rsAstralRange + ']', | ||
rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', | ||
rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', | ||
rsZWJ = '\\u200d'; | ||
/** Used to compose unicode regexes. */ | ||
var reOptMod = rsModifier + '?', | ||
rsOptVar = '[' + rsVarRange + ']?', | ||
rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', | ||
rsSeq = rsOptVar + reOptMod + rsOptJoin, | ||
rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; | ||
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ | ||
var reComplexSymbol = RegExp(rsSymbol + rsSeq, 'g'); | ||
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ | ||
var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); | ||
/** | ||
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) | ||
* of an array-like value. | ||
* Gets the number of symbols in `string`. | ||
* | ||
* @param {string} string The string to inspect. | ||
* @returns {number} Returns the string size. | ||
*/ | ||
var MAX_SAFE_INTEGER = 9007199254740991; | ||
function stringSize(string) { | ||
if (!(string && reHasComplexSymbol.test(string))) { | ||
return string.length; | ||
} | ||
var result = reComplexSymbol.lastIndex = 0; | ||
while (reComplexSymbol.test(string)) { | ||
result++; | ||
} | ||
return result; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** | ||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
@@ -44,9 +99,134 @@ * | ||
/** | ||
* Gets the size of `collection` by returning its length for array-like | ||
* values or the number of own enumerable properties for objects. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Collection | ||
* @param {Array|Object} collection The collection to inspect. | ||
* @returns {number} Returns the collection size. | ||
* @example | ||
* | ||
* _.size([1, 2, 3]); | ||
* // => 3 | ||
* | ||
* _.size({ 'a': 1, 'b': 2 }); | ||
* // => 2 | ||
* | ||
* _.size('pebbles'); | ||
* // => 7 | ||
*/ | ||
function size(collection) { | ||
if (collection == null) { | ||
return 0; | ||
} | ||
if (isArrayLike(collection)) { | ||
var result = collection.length; | ||
return (result && isString(collection)) ? stringSize(collection) : result; | ||
} | ||
return keys(collection).length; | ||
} | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
var isArray = Array.isArray; | ||
/** | ||
* Checks if `value` is array-like. A value is considered array-like if it's | ||
* not a function and has a `value.length` that's an integer greater than or | ||
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is array-like, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLike(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLike('abc'); | ||
* // => true | ||
* | ||
* _.isArrayLike(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLike(value) { | ||
return value != null && | ||
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value)); | ||
} | ||
/** | ||
* 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 a valid array-like length. | ||
* | ||
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength). | ||
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* | ||
* @private | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @example | ||
* | ||
* _.isLength(3); | ||
* // => true | ||
* | ||
* _.isLength(Number.MIN_VALUE); | ||
* // => false | ||
* | ||
* _.isLength(Infinity); | ||
* // => false | ||
* | ||
* _.isLength('3'); | ||
* // => false | ||
*/ | ||
@@ -58,26 +238,79 @@ function isLength(value) { | ||
/** | ||
* Gets the size of `collection` by returning its length for array-like | ||
* values or the number of own enumerable properties for objects. | ||
* 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 Collection | ||
* @param {Array|Object|string} collection The collection to inspect. | ||
* @returns {number} Returns the size of `collection`. | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.size([1, 2, 3]); | ||
* // => 3 | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.size({ 'a': 1, 'b': 2 }); | ||
* // => 2 | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.size('pebbles'); | ||
* // => 7 | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function size(collection) { | ||
var length = collection ? getLength(collection) : 0; | ||
return isLength(length) ? length : keys(collection).length; | ||
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 `String` 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 | ||
* | ||
* _.isString('abc'); | ||
* // => true | ||
* | ||
* _.isString(1); | ||
* // => false | ||
*/ | ||
function isString(value) { | ||
return typeof value == 'string' || | ||
(!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag); | ||
} | ||
module.exports = size; |
{ | ||
"name": "lodash.size", | ||
"version": "3.0.2", | ||
"description": "The modern build of lodash’s `_.size` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.size` 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, size", | ||
"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/)" | ||
@@ -20,4 +18,4 @@ ], | ||
"dependencies": { | ||
"lodash.keys": "^3.0.0" | ||
"lodash.keys": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.size v3.0.2 | ||
# lodash.size v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.size` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.size` 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 size = require('lodash.size'); | ||
See the [documentation](https://lodash.com/docs#size) or [package source](https://github.com/lodash/lodash/blob/3.0.2-npm-packages/lodash.size) for more details. | ||
See the [documentation](https://lodash.com/docs#size) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.size) for more details. |
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
10945
292
19
1
+ Addedlodash.keys@4.2.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
Updatedlodash.keys@^4.0.0