Initial commit
[yaffs-website] / node_modules / lodash.isarray / index.js
1 /**
2  * lodash 3.0.4 (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 /** `Object#toString` result references. */
11 var arrayTag = '[object Array]',
12     funcTag = '[object Function]';
13
14 /** Used to detect host constructors (Safari > 5). */
15 var reIsHostCtor = /^\[object .+?Constructor\]$/;
16
17 /**
18  * Checks if `value` is object-like.
19  *
20  * @private
21  * @param {*} value The value to check.
22  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
23  */
24 function isObjectLike(value) {
25   return !!value && typeof value == 'object';
26 }
27
28 /** Used for native method references. */
29 var objectProto = Object.prototype;
30
31 /** Used to resolve the decompiled source of functions. */
32 var fnToString = Function.prototype.toString;
33
34 /** Used to check objects for own properties. */
35 var hasOwnProperty = objectProto.hasOwnProperty;
36
37 /**
38  * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
39  * of values.
40  */
41 var objToString = objectProto.toString;
42
43 /** Used to detect if a method is native. */
44 var reIsNative = RegExp('^' +
45   fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
46   .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
47 );
48
49 /* Native method references for those with the same name as other `lodash` methods. */
50 var nativeIsArray = getNative(Array, 'isArray');
51
52 /**
53  * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
54  * of an array-like value.
55  */
56 var MAX_SAFE_INTEGER = 9007199254740991;
57
58 /**
59  * Gets the native function at `key` of `object`.
60  *
61  * @private
62  * @param {Object} object The object to query.
63  * @param {string} key The key of the method to get.
64  * @returns {*} Returns the function if it's native, else `undefined`.
65  */
66 function getNative(object, key) {
67   var value = object == null ? undefined : object[key];
68   return isNative(value) ? value : undefined;
69 }
70
71 /**
72  * Checks if `value` is a valid array-like length.
73  *
74  * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
75  *
76  * @private
77  * @param {*} value The value to check.
78  * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
79  */
80 function isLength(value) {
81   return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
82 }
83
84 /**
85  * Checks if `value` is classified as an `Array` object.
86  *
87  * @static
88  * @memberOf _
89  * @category Lang
90  * @param {*} value The value to check.
91  * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
92  * @example
93  *
94  * _.isArray([1, 2, 3]);
95  * // => true
96  *
97  * _.isArray(function() { return arguments; }());
98  * // => false
99  */
100 var isArray = nativeIsArray || function(value) {
101   return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
102 };
103
104 /**
105  * Checks if `value` is classified as a `Function` object.
106  *
107  * @static
108  * @memberOf _
109  * @category Lang
110  * @param {*} value The value to check.
111  * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
112  * @example
113  *
114  * _.isFunction(_);
115  * // => true
116  *
117  * _.isFunction(/abc/);
118  * // => false
119  */
120 function isFunction(value) {
121   // The use of `Object#toString` avoids issues with the `typeof` operator
122   // in older versions of Chrome and Safari which return 'function' for regexes
123   // and Safari 8 equivalents which return 'object' for typed array constructors.
124   return isObject(value) && objToString.call(value) == funcTag;
125 }
126
127 /**
128  * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
129  * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
130  *
131  * @static
132  * @memberOf _
133  * @category Lang
134  * @param {*} value The value to check.
135  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
136  * @example
137  *
138  * _.isObject({});
139  * // => true
140  *
141  * _.isObject([1, 2, 3]);
142  * // => true
143  *
144  * _.isObject(1);
145  * // => false
146  */
147 function isObject(value) {
148   // Avoid a V8 JIT bug in Chrome 19-20.
149   // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
150   var type = typeof value;
151   return !!value && (type == 'object' || type == 'function');
152 }
153
154 /**
155  * Checks if `value` is a native function.
156  *
157  * @static
158  * @memberOf _
159  * @category Lang
160  * @param {*} value The value to check.
161  * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
162  * @example
163  *
164  * _.isNative(Array.prototype.push);
165  * // => true
166  *
167  * _.isNative(_);
168  * // => false
169  */
170 function isNative(value) {
171   if (value == null) {
172     return false;
173   }
174   if (isFunction(value)) {
175     return reIsNative.test(fnToString.call(value));
176   }
177   return isObjectLike(value) && reIsHostCtor.test(value);
178 }
179
180 module.exports = isArray;