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>
10 /** `Object#toString` result references. */
11 var arrayTag = '[object Array]',
12 funcTag = '[object Function]';
14 /** Used to detect host constructors (Safari > 5). */
15 var reIsHostCtor = /^\[object .+?Constructor\]$/;
18 * Checks if `value` is object-like.
21 * @param {*} value The value to check.
22 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
24 function isObjectLike(value) {
25 return !!value && typeof value == 'object';
28 /** Used for native method references. */
29 var objectProto = Object.prototype;
31 /** Used to resolve the decompiled source of functions. */
32 var fnToString = Function.prototype.toString;
34 /** Used to check objects for own properties. */
35 var hasOwnProperty = objectProto.hasOwnProperty;
38 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
41 var objToString = objectProto.toString;
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.*?') + '$'
49 /* Native method references for those with the same name as other `lodash` methods. */
50 var nativeIsArray = getNative(Array, 'isArray');
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.
56 var MAX_SAFE_INTEGER = 9007199254740991;
59 * Gets the native function at `key` of `object`.
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`.
66 function getNative(object, key) {
67 var value = object == null ? undefined : object[key];
68 return isNative(value) ? value : undefined;
72 * Checks if `value` is a valid array-like length.
74 * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
77 * @param {*} value The value to check.
78 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
80 function isLength(value) {
81 return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
85 * Checks if `value` is classified as an `Array` object.
90 * @param {*} value The value to check.
91 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
94 * _.isArray([1, 2, 3]);
97 * _.isArray(function() { return arguments; }());
100 var isArray = nativeIsArray || function(value) {
101 return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
105 * Checks if `value` is classified as a `Function` object.
110 * @param {*} value The value to check.
111 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
117 * _.isFunction(/abc/);
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;
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('')`)
134 * @param {*} value The value to check.
135 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
141 * _.isObject([1, 2, 3]);
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');
155 * Checks if `value` is a native function.
160 * @param {*} value The value to check.
161 * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
164 * _.isNative(Array.prototype.push);
170 function isNative(value) {
174 if (isFunction(value)) {
175 return reIsNative.test(fnToString.call(value));
177 return isObjectLike(value) && reIsHostCtor.test(value);
180 module.exports = isArray;