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
10 /** Used as references for various `Number` constants. */
11 var MAX_SAFE_INTEGER = 9007199254740991;
13 /** `Object#toString` result references. */
14 var argsTag = '[object Arguments]',
15 funcTag = '[object Function]',
16 genTag = '[object GeneratorFunction]';
18 /** Used for built-in method references. */
19 var objectProto = Object.prototype;
21 /** Used to check objects for own properties. */
22 var hasOwnProperty = objectProto.hasOwnProperty;
26 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
29 var objectToString = objectProto.toString;
31 /** Built-in value references. */
32 var propertyIsEnumerable = objectProto.propertyIsEnumerable;
35 * Checks if `value` is likely an `arguments` object.
41 * @param {*} value The value to check.
42 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
46 * _.isArguments(function() { return arguments; }());
49 * _.isArguments([1, 2, 3]);
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);
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`.
67 * @param {*} value The value to check.
68 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
71 * _.isArrayLike([1, 2, 3]);
74 * _.isArrayLike(document.body.children);
77 * _.isArrayLike('abc');
80 * _.isArrayLike(_.noop);
83 function isArrayLike(value) {
84 return value != null && isLength(value.length) && !isFunction(value);
88 * This method is like `_.isArrayLike` except that it also checks if `value`
95 * @param {*} value The value to check.
96 * @returns {boolean} Returns `true` if `value` is an array-like object,
100 * _.isArrayLikeObject([1, 2, 3]);
103 * _.isArrayLikeObject(document.body.children);
106 * _.isArrayLikeObject('abc');
109 * _.isArrayLikeObject(_.noop);
112 function isArrayLikeObject(value) {
113 return isObjectLike(value) && isArrayLike(value);
117 * Checks if `value` is classified as a `Function` object.
123 * @param {*} value The value to check.
124 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
130 * _.isFunction(/abc/);
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;
141 * Checks if `value` is a valid array-like length.
143 * **Note:** This method is loosely based on
144 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
150 * @param {*} value The value to check.
151 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
157 * _.isLength(Number.MIN_VALUE);
160 * _.isLength(Infinity);
166 function isLength(value) {
167 return typeof value == 'number' &&
168 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
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('')`)
180 * @param {*} value The value to check.
181 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
187 * _.isObject([1, 2, 3]);
190 * _.isObject(_.noop);
196 function isObject(value) {
197 var type = typeof value;
198 return !!value && (type == 'object' || type == 'function');
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".
209 * @param {*} value The value to check.
210 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
213 * _.isObjectLike({});
216 * _.isObjectLike([1, 2, 3]);
219 * _.isObjectLike(_.noop);
222 * _.isObjectLike(null);
225 function isObjectLike(value) {
226 return !!value && typeof value == 'object';
229 module.exports = isArguments;