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. */
13 /** `Object#toString` result references. */
14 var symbolTag = '[object Symbol]';
16 /** Used to determine if values are of the language type `Object`. */
22 /** Detect free variable `exports`. */
23 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
27 /** Detect free variable `module`. */
28 var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
32 /** Detect free variable `global` from Node.js. */
33 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
35 /** Detect free variable `self`. */
36 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
38 /** Detect free variable `window`. */
39 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
41 /** Detect `this` as the global object. */
42 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
45 * Used as a reference to the global object.
47 * The `this` value is used if it's the global object to avoid Greasemonkey's
48 * restricted `window` object, otherwise the `window` object is used.
50 var root = freeGlobal ||
51 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
52 freeSelf || thisGlobal || Function('return this')();
55 * Checks if `value` is a global object.
58 * @param {*} value The value to check.
59 * @returns {null|Object} Returns `value` if it's a global object, else `null`.
61 function checkGlobal(value) {
62 return (value && value.Object === Object) ? value : null;
65 /** Used for built-in method references. */
66 var objectProto = Object.prototype;
70 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
73 var objectToString = objectProto.toString;
75 /** Built-in value references. */
76 var Symbol = root.Symbol;
78 /** Used to convert symbols to primitives and strings. */
79 var symbolProto = Symbol ? Symbol.prototype : undefined,
80 symbolToString = symbolProto ? symbolProto.toString : undefined;
83 * The base implementation of `_.toString` which doesn't convert nullish
84 * values to empty strings.
87 * @param {*} value The value to process.
88 * @returns {string} Returns the string.
90 function baseToString(value) {
91 // Exit early for strings to avoid a performance hit in some environments.
92 if (typeof value == 'string') {
95 if (isSymbol(value)) {
96 return symbolToString ? symbolToString.call(value) : '';
98 var result = (value + '');
99 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
103 * Checks if `value` is object-like. A value is object-like if it's not `null`
104 * and has a `typeof` result of "object".
110 * @param {*} value The value to check.
111 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
114 * _.isObjectLike({});
117 * _.isObjectLike([1, 2, 3]);
120 * _.isObjectLike(_.noop);
123 * _.isObjectLike(null);
126 function isObjectLike(value) {
127 return !!value && typeof value == 'object';
131 * Checks if `value` is classified as a `Symbol` primitive or object.
137 * @param {*} value The value to check.
138 * @returns {boolean} Returns `true` if `value` is correctly classified,
142 * _.isSymbol(Symbol.iterator);
148 function isSymbol(value) {
149 return typeof value == 'symbol' ||
150 (isObjectLike(value) && objectToString.call(value) == symbolTag);
153 module.exports = baseToString;