Initial commit
[yaffs-website] / node_modules / lodash.isarguments / index.js
1 /**
2  * lodash (Custom Build) <https://lodash.com/>
3  * Build: `lodash modularize exports="npm" -o ./`
4  * Copyright jQuery Foundation and other contributors <https://jquery.org/>
5  * Released under MIT license <https://lodash.com/license>
6  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8  */
9
10 /** Used as references for various `Number` constants. */
11 var MAX_SAFE_INTEGER = 9007199254740991;
12
13 /** `Object#toString` result references. */
14 var argsTag = '[object Arguments]',
15     funcTag = '[object Function]',
16     genTag = '[object GeneratorFunction]';
17
18 /** Used for built-in method references. */
19 var objectProto = Object.prototype;
20
21 /** Used to check objects for own properties. */
22 var hasOwnProperty = objectProto.hasOwnProperty;
23
24 /**
25  * Used to resolve the
26  * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
27  * of values.
28  */
29 var objectToString = objectProto.toString;
30
31 /** Built-in value references. */
32 var propertyIsEnumerable = objectProto.propertyIsEnumerable;
33
34 /**
35  * Checks if `value` is likely an `arguments` object.
36  *
37  * @static
38  * @memberOf _
39  * @since 0.1.0
40  * @category Lang
41  * @param {*} value The value to check.
42  * @returns {boolean} Returns `true` if `value` is an `arguments` object,
43  *  else `false`.
44  * @example
45  *
46  * _.isArguments(function() { return arguments; }());
47  * // => true
48  *
49  * _.isArguments([1, 2, 3]);
50  * // => false
51  */
52 function isArguments(value) {
53   // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
54   return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
55     (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
56 }
57
58 /**
59  * Checks if `value` is array-like. A value is considered array-like if it's
60  * not a function and has a `value.length` that's an integer greater than or
61  * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
62  *
63  * @static
64  * @memberOf _
65  * @since 4.0.0
66  * @category Lang
67  * @param {*} value The value to check.
68  * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
69  * @example
70  *
71  * _.isArrayLike([1, 2, 3]);
72  * // => true
73  *
74  * _.isArrayLike(document.body.children);
75  * // => true
76  *
77  * _.isArrayLike('abc');
78  * // => true
79  *
80  * _.isArrayLike(_.noop);
81  * // => false
82  */
83 function isArrayLike(value) {
84   return value != null && isLength(value.length) && !isFunction(value);
85 }
86
87 /**
88  * This method is like `_.isArrayLike` except that it also checks if `value`
89  * is an object.
90  *
91  * @static
92  * @memberOf _
93  * @since 4.0.0
94  * @category Lang
95  * @param {*} value The value to check.
96  * @returns {boolean} Returns `true` if `value` is an array-like object,
97  *  else `false`.
98  * @example
99  *
100  * _.isArrayLikeObject([1, 2, 3]);
101  * // => true
102  *
103  * _.isArrayLikeObject(document.body.children);
104  * // => true
105  *
106  * _.isArrayLikeObject('abc');
107  * // => false
108  *
109  * _.isArrayLikeObject(_.noop);
110  * // => false
111  */
112 function isArrayLikeObject(value) {
113   return isObjectLike(value) && isArrayLike(value);
114 }
115
116 /**
117  * Checks if `value` is classified as a `Function` object.
118  *
119  * @static
120  * @memberOf _
121  * @since 0.1.0
122  * @category Lang
123  * @param {*} value The value to check.
124  * @returns {boolean} Returns `true` if `value` is a function, else `false`.
125  * @example
126  *
127  * _.isFunction(_);
128  * // => true
129  *
130  * _.isFunction(/abc/);
131  * // => false
132  */
133 function isFunction(value) {
134   // The use of `Object#toString` avoids issues with the `typeof` operator
135   // in Safari 8-9 which returns 'object' for typed array and other constructors.
136   var tag = isObject(value) ? objectToString.call(value) : '';
137   return tag == funcTag || tag == genTag;
138 }
139
140 /**
141  * Checks if `value` is a valid array-like length.
142  *
143  * **Note:** This method is loosely based on
144  * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
145  *
146  * @static
147  * @memberOf _
148  * @since 4.0.0
149  * @category Lang
150  * @param {*} value The value to check.
151  * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
152  * @example
153  *
154  * _.isLength(3);
155  * // => true
156  *
157  * _.isLength(Number.MIN_VALUE);
158  * // => false
159  *
160  * _.isLength(Infinity);
161  * // => false
162  *
163  * _.isLength('3');
164  * // => false
165  */
166 function isLength(value) {
167   return typeof value == 'number' &&
168     value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
169 }
170
171 /**
172  * Checks if `value` is the
173  * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
174  * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
175  *
176  * @static
177  * @memberOf _
178  * @since 0.1.0
179  * @category Lang
180  * @param {*} value The value to check.
181  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
182  * @example
183  *
184  * _.isObject({});
185  * // => true
186  *
187  * _.isObject([1, 2, 3]);
188  * // => true
189  *
190  * _.isObject(_.noop);
191  * // => true
192  *
193  * _.isObject(null);
194  * // => false
195  */
196 function isObject(value) {
197   var type = typeof value;
198   return !!value && (type == 'object' || type == 'function');
199 }
200
201 /**
202  * Checks if `value` is object-like. A value is object-like if it's not `null`
203  * and has a `typeof` result of "object".
204  *
205  * @static
206  * @memberOf _
207  * @since 4.0.0
208  * @category Lang
209  * @param {*} value The value to check.
210  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
211  * @example
212  *
213  * _.isObjectLike({});
214  * // => true
215  *
216  * _.isObjectLike([1, 2, 3]);
217  * // => true
218  *
219  * _.isObjectLike(_.noop);
220  * // => false
221  *
222  * _.isObjectLike(null);
223  * // => false
224  */
225 function isObjectLike(value) {
226   return !!value && typeof value == 'object';
227 }
228
229 module.exports = isArguments;