Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80728 views
1
/**
2
* lodash 3.0.3 (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
/**
15
* Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
16
* In addition to special characters the forward slash is escaped to allow for
17
* easier `eval` use and `Function` compilation.
18
*/
19
var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
20
reHasRegExpChars = RegExp(reRegExpChars.source);
21
22
/** Used to detect host constructors (Safari > 5). */
23
var reIsHostCtor = /^\[object .+?Constructor\]$/;
24
25
/**
26
* Converts `value` to a string if it's not one. An empty string is returned
27
* for `null` or `undefined` values.
28
*
29
* @private
30
* @param {*} value The value to process.
31
* @returns {string} Returns the string.
32
*/
33
function baseToString(value) {
34
if (typeof value == 'string') {
35
return value;
36
}
37
return value == null ? '' : (value + '');
38
}
39
40
/**
41
* Checks if `value` is object-like.
42
*
43
* @private
44
* @param {*} value The value to check.
45
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
46
*/
47
function isObjectLike(value) {
48
return !!value && typeof value == 'object';
49
}
50
51
/** Used for native method references. */
52
var objectProto = Object.prototype;
53
54
/** Used to resolve the decompiled source of functions. */
55
var fnToString = Function.prototype.toString;
56
57
/** Used to check objects for own properties. */
58
var hasOwnProperty = objectProto.hasOwnProperty;
59
60
/**
61
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
62
* of values.
63
*/
64
var objToString = objectProto.toString;
65
66
/** Used to detect if a method is native. */
67
var reIsNative = RegExp('^' +
68
escapeRegExp(fnToString.call(hasOwnProperty))
69
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
70
);
71
72
/* Native method references for those with the same name as other `lodash` methods. */
73
var nativeIsArray = getNative(Array, 'isArray');
74
75
/**
76
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
77
* of an array-like value.
78
*/
79
var MAX_SAFE_INTEGER = 9007199254740991;
80
81
/**
82
* Gets the native function at `key` of `object`.
83
*
84
* @private
85
* @param {Object} object The object to query.
86
* @param {string} key The key of the method to get.
87
* @returns {*} Returns the function if it's native, else `undefined`.
88
*/
89
function getNative(object, key) {
90
var value = object == null ? undefined : object[key];
91
return isNative(value) ? value : undefined;
92
}
93
94
/**
95
* Checks if `value` is a valid array-like length.
96
*
97
* **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
98
*
99
* @private
100
* @param {*} value The value to check.
101
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
102
*/
103
function isLength(value) {
104
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
105
}
106
107
/**
108
* Checks if `value` is classified as an `Array` object.
109
*
110
* @static
111
* @memberOf _
112
* @category Lang
113
* @param {*} value The value to check.
114
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
115
* @example
116
*
117
* _.isArray([1, 2, 3]);
118
* // => true
119
*
120
* _.isArray(function() { return arguments; }());
121
* // => false
122
*/
123
var isArray = nativeIsArray || function(value) {
124
return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
125
};
126
127
/**
128
* Checks if `value` is a native function.
129
*
130
* @static
131
* @memberOf _
132
* @category Lang
133
* @param {*} value The value to check.
134
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
135
* @example
136
*
137
* _.isNative(Array.prototype.push);
138
* // => true
139
*
140
* _.isNative(_);
141
* // => false
142
*/
143
function isNative(value) {
144
if (value == null) {
145
return false;
146
}
147
if (objToString.call(value) == funcTag) {
148
return reIsNative.test(fnToString.call(value));
149
}
150
return isObjectLike(value) && reIsHostCtor.test(value);
151
}
152
153
/**
154
* Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
155
* "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
156
*
157
* @static
158
* @memberOf _
159
* @category String
160
* @param {string} [string=''] The string to escape.
161
* @returns {string} Returns the escaped string.
162
* @example
163
*
164
* _.escapeRegExp('[lodash](https://lodash.com/)');
165
* // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
166
*/
167
function escapeRegExp(string) {
168
string = baseToString(string);
169
return (string && reHasRegExpChars.test(string))
170
? string.replace(reRegExpChars, '\\$&')
171
: string;
172
}
173
174
module.exports = isArray;
175
176