Initial commit
[yaffs-website] / node_modules / lodash._isiterateecall / index.js
1 /**
2  * lodash 3.0.9 (Custom Build) <https://lodash.com/>
3  * Build: `lodash modern modularize exports="npm" -o ./`
4  * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
5  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
6  * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
7  * Available under MIT license <https://lodash.com/license>
8  */
9
10 /** Used to detect unsigned integer values. */
11 var reIsUint = /^\d+$/;
12
13 /**
14  * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
15  * of an array-like value.
16  */
17 var MAX_SAFE_INTEGER = 9007199254740991;
18
19 /**
20  * The base implementation of `_.property` without support for deep paths.
21  *
22  * @private
23  * @param {string} key The key of the property to get.
24  * @returns {Function} Returns the new function.
25  */
26 function baseProperty(key) {
27   return function(object) {
28     return object == null ? undefined : object[key];
29   };
30 }
31
32 /**
33  * Gets the "length" property value of `object`.
34  *
35  * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
36  * that affects Safari on at least iOS 8.1-8.3 ARM64.
37  *
38  * @private
39  * @param {Object} object The object to query.
40  * @returns {*} Returns the "length" value.
41  */
42 var getLength = baseProperty('length');
43
44 /**
45  * Checks if `value` is array-like.
46  *
47  * @private
48  * @param {*} value The value to check.
49  * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
50  */
51 function isArrayLike(value) {
52   return value != null && isLength(getLength(value));
53 }
54
55 /**
56  * Checks if `value` is a valid array-like index.
57  *
58  * @private
59  * @param {*} value The value to check.
60  * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
61  * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
62  */
63 function isIndex(value, length) {
64   value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
65   length = length == null ? MAX_SAFE_INTEGER : length;
66   return value > -1 && value % 1 == 0 && value < length;
67 }
68
69 /**
70  * Checks if the provided arguments are from an iteratee call.
71  *
72  * @private
73  * @param {*} value The potential iteratee value argument.
74  * @param {*} index The potential iteratee index or key argument.
75  * @param {*} object The potential iteratee object argument.
76  * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
77  */
78 function isIterateeCall(value, index, object) {
79   if (!isObject(object)) {
80     return false;
81   }
82   var type = typeof index;
83   if (type == 'number'
84       ? (isArrayLike(object) && isIndex(index, object.length))
85       : (type == 'string' && index in object)) {
86     var other = object[index];
87     return value === value ? (value === other) : (other !== other);
88   }
89   return false;
90 }
91
92 /**
93  * Checks if `value` is a valid array-like length.
94  *
95  * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
96  *
97  * @private
98  * @param {*} value The value to check.
99  * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
100  */
101 function isLength(value) {
102   return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
103 }
104
105 /**
106  * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
107  * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
108  *
109  * @static
110  * @memberOf _
111  * @category Lang
112  * @param {*} value The value to check.
113  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
114  * @example
115  *
116  * _.isObject({});
117  * // => true
118  *
119  * _.isObject([1, 2, 3]);
120  * // => true
121  *
122  * _.isObject(1);
123  * // => false
124  */
125 function isObject(value) {
126   // Avoid a V8 JIT bug in Chrome 19-20.
127   // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
128   var type = typeof value;
129   return !!value && (type == 'object' || type == 'function');
130 }
131
132 module.exports = isIterateeCall;