154 lines
4.2 KiB
JavaScript
154 lines
4.2 KiB
JavaScript
|
/**
|
||
|
* lodash (Custom Build) <https://lodash.com/>
|
||
|
* Build: `lodash modularize exports="npm" -o ./`
|
||
|
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
||
|
* Released under MIT license <https://lodash.com/license>
|
||
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||
|
*/
|
||
|
|
||
|
/** Used as references for various `Number` constants. */
|
||
|
var INFINITY = 1 / 0;
|
||
|
|
||
|
/** `Object#toString` result references. */
|
||
|
var symbolTag = '[object Symbol]';
|
||
|
|
||
|
/** Used to determine if values are of the language type `Object`. */
|
||
|
var objectTypes = {
|
||
|
'function': true,
|
||
|
'object': true
|
||
|
};
|
||
|
|
||
|
/** Detect free variable `exports`. */
|
||
|
var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
|
||
|
? exports
|
||
|
: undefined;
|
||
|
|
||
|
/** Detect free variable `module`. */
|
||
|
var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
|
||
|
? module
|
||
|
: undefined;
|
||
|
|
||
|
/** Detect free variable `global` from Node.js. */
|
||
|
var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
|
||
|
|
||
|
/** Detect free variable `self`. */
|
||
|
var freeSelf = checkGlobal(objectTypes[typeof self] && self);
|
||
|
|
||
|
/** Detect free variable `window`. */
|
||
|
var freeWindow = checkGlobal(objectTypes[typeof window] && window);
|
||
|
|
||
|
/** Detect `this` as the global object. */
|
||
|
var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
|
||
|
|
||
|
/**
|
||
|
* Used as a reference to the global object.
|
||
|
*
|
||
|
* The `this` value is used if it's the global object to avoid Greasemonkey's
|
||
|
* restricted `window` object, otherwise the `window` object is used.
|
||
|
*/
|
||
|
var root = freeGlobal ||
|
||
|
((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
|
||
|
freeSelf || thisGlobal || Function('return this')();
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is a global object.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {null|Object} Returns `value` if it's a global object, else `null`.
|
||
|
*/
|
||
|
function checkGlobal(value) {
|
||
|
return (value && value.Object === Object) ? value : null;
|
||
|
}
|
||
|
|
||
|
/** Used for built-in method references. */
|
||
|
var objectProto = Object.prototype;
|
||
|
|
||
|
/**
|
||
|
* Used to resolve the
|
||
|
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
||
|
* of values.
|
||
|
*/
|
||
|
var objectToString = objectProto.toString;
|
||
|
|
||
|
/** Built-in value references. */
|
||
|
var Symbol = root.Symbol;
|
||
|
|
||
|
/** Used to convert symbols to primitives and strings. */
|
||
|
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
||
|
symbolToString = symbolProto ? symbolProto.toString : undefined;
|
||
|
|
||
|
/**
|
||
|
* The base implementation of `_.toString` which doesn't convert nullish
|
||
|
* values to empty strings.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {*} value The value to process.
|
||
|
* @returns {string} Returns the string.
|
||
|
*/
|
||
|
function baseToString(value) {
|
||
|
// Exit early for strings to avoid a performance hit in some environments.
|
||
|
if (typeof value == 'string') {
|
||
|
return value;
|
||
|
}
|
||
|
if (isSymbol(value)) {
|
||
|
return symbolToString ? symbolToString.call(value) : '';
|
||
|
}
|
||
|
var result = (value + '');
|
||
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
||
|
* and has a `typeof` result of "object".
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category Lang
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
||
|
* @example
|
||
|
*
|
||
|
* _.isObjectLike({});
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isObjectLike([1, 2, 3]);
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isObjectLike(_.noop);
|
||
|
* // => false
|
||
|
*
|
||
|
* _.isObjectLike(null);
|
||
|
* // => false
|
||
|
*/
|
||
|
function isObjectLike(value) {
|
||
|
return !!value && typeof value == 'object';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is classified as a `Symbol` primitive or object.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @since 4.0.0
|
||
|
* @category Lang
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {boolean} Returns `true` if `value` is correctly classified,
|
||
|
* else `false`.
|
||
|
* @example
|
||
|
*
|
||
|
* _.isSymbol(Symbol.iterator);
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isSymbol('abc');
|
||
|
* // => false
|
||
|
*/
|
||
|
function isSymbol(value) {
|
||
|
return typeof value == 'symbol' ||
|
||
|
(isObjectLike(value) && objectToString.call(value) == symbolTag);
|
||
|
}
|
||
|
|
||
|
module.exports = baseToString;
|