Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81145 views
1
/**
2
* lodash 3.9.0 (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 funcTag = '[object Function]';
12
13
/**
14
* Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).
15
* In addition to special characters the forward slash is escaped to allow for
16
* easier `eval` use and `Function` compilation.
17
*/
18
var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,
19
reHasRegExpChars = RegExp(reRegExpChars.source);
20
21
/** Used to detect host constructors (Safari > 5). */
22
var reIsHostCtor = /^\[object .+?Constructor\]$/;
23
24
/**
25
* Converts `value` to a string if it's not one. An empty string is returned
26
* for `null` or `undefined` values.
27
*
28
* @private
29
* @param {*} value The value to process.
30
* @returns {string} Returns the string.
31
*/
32
function baseToString(value) {
33
if (typeof value == 'string') {
34
return value;
35
}
36
return value == null ? '' : (value + '');
37
}
38
39
/**
40
* Checks if `value` is object-like.
41
*
42
* @private
43
* @param {*} value The value to check.
44
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
45
*/
46
function isObjectLike(value) {
47
return !!value && typeof value == 'object';
48
}
49
50
/** Used for native method references. */
51
var objectProto = Object.prototype;
52
53
/** Used to resolve the decompiled source of functions. */
54
var fnToString = Function.prototype.toString;
55
56
/** Used to check objects for own properties. */
57
var hasOwnProperty = objectProto.hasOwnProperty;
58
59
/**
60
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
61
* of values.
62
*/
63
var objToString = objectProto.toString;
64
65
/** Used to detect if a method is native. */
66
var reIsNative = RegExp('^' +
67
escapeRegExp(fnToString.call(hasOwnProperty))
68
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
69
);
70
71
/**
72
* Gets the native function at `key` of `object`.
73
*
74
* @private
75
* @param {Object} object The object to query.
76
* @param {string} key The key of the method to get.
77
* @returns {*} Returns the function if it's native, else `undefined`.
78
*/
79
function getNative(object, key) {
80
var value = object == null ? undefined : object[key];
81
return isNative(value) ? value : undefined;
82
}
83
84
/**
85
* Checks if `value` is a native function.
86
*
87
* @static
88
* @memberOf _
89
* @category Lang
90
* @param {*} value The value to check.
91
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
92
* @example
93
*
94
* _.isNative(Array.prototype.push);
95
* // => true
96
*
97
* _.isNative(_);
98
* // => false
99
*/
100
function isNative(value) {
101
if (value == null) {
102
return false;
103
}
104
if (objToString.call(value) == funcTag) {
105
return reIsNative.test(fnToString.call(value));
106
}
107
return isObjectLike(value) && reIsHostCtor.test(value);
108
}
109
110
/**
111
* Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
112
* "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
113
*
114
* @static
115
* @memberOf _
116
* @category String
117
* @param {string} [string=''] The string to escape.
118
* @returns {string} Returns the escaped string.
119
* @example
120
*
121
* _.escapeRegExp('[lodash](https://lodash.com/)');
122
* // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
123
*/
124
function escapeRegExp(string) {
125
string = baseToString(string);
126
return (string && reHasRegExpChars.test(string))
127
? string.replace(reRegExpChars, '\\$&')
128
: string;
129
}
130
131
module.exports = getNative;
132
133