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 /** Detect free variable `global` from Node.js. */
17 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
19 /** Detect free variable `self`. */
20 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
22 /** Used as a reference to the global object. */
23 var root = freeGlobal || freeSelf || Function('return this')();
25 /** Used for built-in method references. */
26 var objectProto = Object.prototype;
30 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
33 var objectToString = objectProto.toString;
35 /** Built-in value references. */
36 var Symbol = root.Symbol;
38 /** Used to convert symbols to primitives and strings. */
39 var symbolProto = Symbol ? Symbol.prototype : undefined,
40 symbolToString = symbolProto ? symbolProto.toString : undefined;
43 * The base implementation of `_.toString` which doesn't convert nullish
44 * values to empty strings.
47 * @param {*} value The value to process.
48 * @returns {string} Returns the string.
50 function baseToString(value) {
51 // Exit early for strings to avoid a performance hit in some environments.
52 if (typeof value == 'string') {
55 if (isSymbol(value)) {
56 return symbolToString ? symbolToString.call(value) : '';
58 var result = (value + '');
59 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
63 * Checks if `value` is object-like. A value is object-like if it's not `null`
64 * and has a `typeof` result of "object".
70 * @param {*} value The value to check.
71 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
77 * _.isObjectLike([1, 2, 3]);
80 * _.isObjectLike(_.noop);
83 * _.isObjectLike(null);
86 function isObjectLike(value) {
87 return !!value && typeof value == 'object';
91 * Checks if `value` is classified as a `Symbol` primitive or object.
97 * @param {*} value The value to check.
98 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
101 * _.isSymbol(Symbol.iterator);
107 function isSymbol(value) {
108 return typeof value == 'symbol' ||
109 (isObjectLike(value) && objectToString.call(value) == symbolTag);
113 * Converts `value` to a string. An empty string is returned for `null`
114 * and `undefined` values. The sign of `-0` is preserved.
120 * @param {*} value The value to process.
121 * @returns {string} Returns the string.
130 * _.toString([1, 2, 3]);
133 function toString(value) {
134 return value == null ? '' : baseToString(value);
137 module.exports = toString;