lodash.size
Advanced tools
Comparing version 4.1.0 to 4.2.0
305
index.js
@@ -14,4 +14,3 @@ /** | ||
/** `Object#toString` result references. */ | ||
var argsTag = '[object Arguments]', | ||
funcTag = '[object Function]', | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
@@ -29,3 +28,3 @@ mapTag = '[object Map]', | ||
* Used to match `RegExp` | ||
* [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). | ||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). | ||
*/ | ||
@@ -37,5 +36,2 @@ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
/** Used to detect unsigned integer values. */ | ||
var reIsUint = /^(?:0|[1-9]\d*)$/; | ||
/** Used to compose unicode character classes. */ | ||
@@ -65,6 +61,6 @@ var rsAstralRange = '\\ud800-\\udfff', | ||
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ | ||
var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); | ||
var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + 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 + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); | ||
var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); | ||
@@ -81,2 +77,11 @@ /** Detect free variable `global` from Node.js. */ | ||
/** | ||
* Gets the size of an ASCII `string`. | ||
* | ||
* @private | ||
* @param {string} string The string inspect. | ||
* @returns {number} Returns the string size. | ||
*/ | ||
var asciiSize = baseProperty('length'); | ||
/** | ||
* The base implementation of `_.property` without support for deep paths. | ||
@@ -95,21 +100,2 @@ * | ||
/** | ||
* The base implementation of `_.times` without support for iteratee shorthands | ||
* or max array length checks. | ||
* | ||
* @private | ||
* @param {number} n The number of times to invoke `iteratee`. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns the array of results. | ||
*/ | ||
function baseTimes(n, iteratee) { | ||
var index = -1, | ||
result = Array(n); | ||
while (++index < n) { | ||
result[index] = iteratee(index); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Gets the value at `key` of `object`. | ||
@@ -127,2 +113,13 @@ * | ||
/** | ||
* Checks if `string` contains Unicode symbols. | ||
* | ||
* @private | ||
* @param {string} string The string to inspect. | ||
* @returns {boolean} Returns `true` if a symbol is found, else `false`. | ||
*/ | ||
function hasUnicode(string) { | ||
return reHasUnicode.test(string); | ||
} | ||
/** | ||
* Checks if `value` is a host object in IE < 9. | ||
@@ -147,3 +144,3 @@ * | ||
/** | ||
* Creates a function that invokes `func` with its first argument transformed. | ||
* Creates a unary function that invokes `func` with its argument transformed. | ||
* | ||
@@ -169,7 +166,17 @@ * @private | ||
function stringSize(string) { | ||
if (!(string && reHasComplexSymbol.test(string))) { | ||
return string.length; | ||
} | ||
var result = reComplexSymbol.lastIndex = 0; | ||
while (reComplexSymbol.test(string)) { | ||
return hasUnicode(string) | ||
? unicodeSize(string) | ||
: asciiSize(string); | ||
} | ||
/** | ||
* Gets the size of a Unicode `string`. | ||
* | ||
* @private | ||
* @param {string} string The string inspect. | ||
* @returns {number} Returns the string size. | ||
*/ | ||
function unicodeSize(string) { | ||
var result = reUnicode.lastIndex = 0; | ||
while (reUnicode.test(string)) { | ||
result++; | ||
@@ -181,3 +188,4 @@ } | ||
/** Used for built-in method references. */ | ||
var objectProto = Object.prototype; | ||
var funcProto = Function.prototype, | ||
objectProto = Object.prototype; | ||
@@ -194,3 +202,3 @@ /** Used to detect overreaching core-js shims. */ | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString = Function.prototype.toString; | ||
var funcToString = funcProto.toString; | ||
@@ -202,3 +210,3 @@ /** Used to check objects for own properties. */ | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
@@ -214,8 +222,4 @@ */ | ||
/** Built-in value references. */ | ||
var propertyIsEnumerable = objectProto.propertyIsEnumerable; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeGetPrototype = Object.getPrototypeOf, | ||
nativeKeys = Object.keys; | ||
var nativeKeys = overArg(Object.keys, Object); | ||
@@ -248,19 +252,2 @@ /* Built-in method references that are verified to be native. */ | ||
/** | ||
* The base implementation of `_.has` without support for deep paths. | ||
* | ||
* @private | ||
* @param {Object} [object] The object to query. | ||
* @param {Array|string} key The key to check. | ||
* @returns {boolean} Returns `true` if `key` exists, else `false`. | ||
*/ | ||
function baseHas(object, key) { | ||
// Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`, | ||
// that are composed entirely of index properties, return `false` for | ||
// `hasOwnProperty` checks of them. | ||
return object != null && | ||
(hasOwnProperty.call(object, key) || | ||
(typeof object == 'object' && key in object && getPrototype(object) === null)); | ||
} | ||
/** | ||
* The base implementation of `_.isNative` without bad shim checks. | ||
@@ -282,4 +269,3 @@ * | ||
/** | ||
* The base implementation of `_.keys` which doesn't skip the constructor | ||
* property of prototypes or treat sparse arrays as dense. | ||
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense. | ||
* | ||
@@ -290,18 +276,16 @@ * @private | ||
*/ | ||
var baseKeys = overArg(nativeKeys, Object); | ||
function baseKeys(object) { | ||
if (!isPrototype(object)) { | ||
return nativeKeys(object); | ||
} | ||
var result = []; | ||
for (var key in Object(object)) { | ||
if (hasOwnProperty.call(object, key) && key != 'constructor') { | ||
result.push(key); | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Gets the "length" property value of `object`. | ||
* | ||
* **Note:** This function is used to avoid a | ||
* [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects | ||
* Safari on at least iOS 8.1-8.3 ARM64. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {*} Returns the "length" value. | ||
*/ | ||
var getLength = baseProperty('length'); | ||
/** | ||
* Gets the native function at `key` of `object`. | ||
@@ -320,11 +304,2 @@ * | ||
/** | ||
* Gets the `[[Prototype]]` of `value`. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {null|Object} Returns the `[[Prototype]]`. | ||
*/ | ||
var getPrototype = overArg(nativeGetPrototype, Object); | ||
/** | ||
* Gets the `toStringTag` of `value`. | ||
@@ -339,3 +314,3 @@ * | ||
// Fallback for data views, maps, sets, and weak maps in IE 11, | ||
// for data views in Edge, and promises in Node.js. | ||
// for data views in Edge < 14, and promises in Node.js. | ||
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || | ||
@@ -365,34 +340,2 @@ (Map && getTag(new Map) != mapTag) || | ||
/** | ||
* Creates an array of index keys for `object` values of arrays, | ||
* `arguments` objects, and strings, otherwise `null` is returned. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @returns {Array|null} Returns index keys, else `null`. | ||
*/ | ||
function indexKeys(object) { | ||
var length = object ? object.length : undefined; | ||
if (isLength(length) && | ||
(isArray(object) || isString(object) || isArguments(object))) { | ||
return baseTimes(length, String); | ||
} | ||
return null; | ||
} | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* Checks if `func` has its source masked. | ||
@@ -449,3 +392,3 @@ * | ||
* @category Collection | ||
* @param {Array|Object} collection The collection to inspect. | ||
* @param {Array|Object|string} collection The collection to inspect. | ||
* @returns {number} Returns the collection size. | ||
@@ -468,39 +411,12 @@ * @example | ||
if (isArrayLike(collection)) { | ||
var result = collection.length; | ||
return (result && isString(collection)) ? stringSize(collection) : result; | ||
return isString(collection) ? stringSize(collection) : collection.length; | ||
} | ||
if (isObjectLike(collection)) { | ||
var tag = getTag(collection); | ||
if (tag == mapTag || tag == setTag) { | ||
return collection.size; | ||
} | ||
var tag = getTag(collection); | ||
if (tag == mapTag || tag == setTag) { | ||
return collection.size; | ||
} | ||
return keys(collection).length; | ||
return baseKeys(collection).length; | ||
} | ||
/** | ||
* Checks if `value` is likely an `arguments` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an `arguments` object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArguments(function() { return arguments; }()); | ||
* // => true | ||
* | ||
* _.isArguments([1, 2, 3]); | ||
* // => false | ||
*/ | ||
function isArguments(value) { | ||
// Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. | ||
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && | ||
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); | ||
} | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
@@ -556,35 +472,6 @@ * | ||
function isArrayLike(value) { | ||
return value != null && isLength(getLength(value)) && !isFunction(value); | ||
return value != null && isLength(value.length) && !isFunction(value); | ||
} | ||
/** | ||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||
* is an object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array-like object, | ||
* else `false`. | ||
* @example | ||
* | ||
* _.isArrayLikeObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject('abc'); | ||
* // => false | ||
* | ||
* _.isArrayLikeObject(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLikeObject(value) { | ||
return isObjectLike(value) && isArrayLike(value); | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
@@ -608,4 +495,3 @@ * | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array and weak map constructors, | ||
// and PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
// in Safari 8-9 which returns 'object' for typed array and other constructors. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
@@ -618,4 +504,4 @@ return tag == funcTag || tag == genTag; | ||
* | ||
* **Note:** This function is loosely based on | ||
* [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). | ||
* **Note:** This method is loosely based on | ||
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). | ||
* | ||
@@ -627,4 +513,3 @@ * @static | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, | ||
* else `false`. | ||
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`. | ||
* @example | ||
@@ -651,3 +536,3 @@ * | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
@@ -730,50 +615,2 @@ * | ||
/** | ||
* Creates an array of the own enumerable property names of `object`. | ||
* | ||
* **Note:** Non-object values are coerced to objects. See the | ||
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) | ||
* for more details. | ||
* | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @returns {Array} Returns the array of property names. | ||
* @example | ||
* | ||
* function Foo() { | ||
* this.a = 1; | ||
* this.b = 2; | ||
* } | ||
* | ||
* Foo.prototype.c = 3; | ||
* | ||
* _.keys(new Foo); | ||
* // => ['a', 'b'] (iteration order is not guaranteed) | ||
* | ||
* _.keys('hi'); | ||
* // => ['0', '1'] | ||
*/ | ||
function keys(object) { | ||
var isProto = isPrototype(object); | ||
if (!(isProto || isArrayLike(object))) { | ||
return baseKeys(object); | ||
} | ||
var indexes = indexKeys(object), | ||
skipIndexes = !!indexes, | ||
result = indexes || [], | ||
length = result.length; | ||
for (var key in object) { | ||
if (baseHas(object, key) && | ||
!(skipIndexes && (key == 'length' || isIndex(key, length))) && | ||
!(isProto && key == 'constructor')) { | ||
result.push(key); | ||
} | ||
} | ||
return result; | ||
} | ||
module.exports = size; |
{ | ||
"name": "lodash.size", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "The lodash method `_.size` exported as a module.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://lodash.com/", |
@@ -1,2 +0,2 @@ | ||
# lodash.size v4.1.0 | ||
# lodash.size v4.2.0 | ||
@@ -18,2 +18,2 @@ The [lodash](https://lodash.com/) method `_.size` exported as a [Node.js](https://nodejs.org/) module. | ||
See the [documentation](https://lodash.com/docs#size) or [package source](https://github.com/lodash/lodash/blob/4.1.0-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.2.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
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
19044
538