react / wstein / node_modules / jest-cli / node_modules / lodash.template / node_modules / lodash.keys / node_modules / lodash._getnative / index.js
81145 views/**1* lodash 3.9.0 (Custom Build) <https://lodash.com/>2* Build: `lodash modern modularize exports="npm" -o ./`3* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>4* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>5* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors6* Available under MIT license <https://lodash.com/license>7*/89/** `Object#toString` result references. */10var funcTag = '[object Function]';1112/**13* Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special).14* In addition to special characters the forward slash is escaped to allow for15* easier `eval` use and `Function` compilation.16*/17var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g,18reHasRegExpChars = RegExp(reRegExpChars.source);1920/** Used to detect host constructors (Safari > 5). */21var reIsHostCtor = /^\[object .+?Constructor\]$/;2223/**24* Converts `value` to a string if it's not one. An empty string is returned25* for `null` or `undefined` values.26*27* @private28* @param {*} value The value to process.29* @returns {string} Returns the string.30*/31function baseToString(value) {32if (typeof value == 'string') {33return value;34}35return value == null ? '' : (value + '');36}3738/**39* Checks if `value` is object-like.40*41* @private42* @param {*} value The value to check.43* @returns {boolean} Returns `true` if `value` is object-like, else `false`.44*/45function isObjectLike(value) {46return !!value && typeof value == 'object';47}4849/** Used for native method references. */50var objectProto = Object.prototype;5152/** Used to resolve the decompiled source of functions. */53var fnToString = Function.prototype.toString;5455/** Used to check objects for own properties. */56var hasOwnProperty = objectProto.hasOwnProperty;5758/**59* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)60* of values.61*/62var objToString = objectProto.toString;6364/** Used to detect if a method is native. */65var reIsNative = RegExp('^' +66escapeRegExp(fnToString.call(hasOwnProperty))67.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'68);6970/**71* Gets the native function at `key` of `object`.72*73* @private74* @param {Object} object The object to query.75* @param {string} key The key of the method to get.76* @returns {*} Returns the function if it's native, else `undefined`.77*/78function getNative(object, key) {79var value = object == null ? undefined : object[key];80return isNative(value) ? value : undefined;81}8283/**84* Checks if `value` is a native function.85*86* @static87* @memberOf _88* @category Lang89* @param {*} value The value to check.90* @returns {boolean} Returns `true` if `value` is a native function, else `false`.91* @example92*93* _.isNative(Array.prototype.push);94* // => true95*96* _.isNative(_);97* // => false98*/99function isNative(value) {100if (value == null) {101return false;102}103if (objToString.call(value) == funcTag) {104return reIsNative.test(fnToString.call(value));105}106return isObjectLike(value) && reIsHostCtor.test(value);107}108109/**110* Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",111* "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.112*113* @static114* @memberOf _115* @category String116* @param {string} [string=''] The string to escape.117* @returns {string} Returns the escaped string.118* @example119*120* _.escapeRegExp('[lodash](https://lodash.com/)');121* // => '\[lodash\]\(https:\/\/lodash\.com\/\)'122*/123function escapeRegExp(string) {124string = baseToString(string);125return (string && reHasRegExpChars.test(string))126? string.replace(reRegExpChars, '\\$&')127: string;128}129130module.exports = getNative;131132133