1e1d2d8f42153219afaf1541c444352111762c52
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / toString.js
1 var Symbol = require('./_Symbol'),
2     isSymbol = require('./isSymbol');
3
4 /** Used as references for various `Number` constants. */
5 var INFINITY = 1 / 0;
6
7 /** Used to convert symbols to primitives and strings. */
8 var symbolProto = Symbol ? Symbol.prototype : undefined,
9     symbolToString = Symbol ? symbolProto.toString : undefined;
10
11 /**
12  * Converts `value` to a string if it's not one. An empty string is returned
13  * for `null` and `undefined` values. The sign of `-0` is preserved.
14  *
15  * @static
16  * @memberOf _
17  * @category Lang
18  * @param {*} value The value to process.
19  * @returns {string} Returns the string.
20  * @example
21  *
22  * _.toString(null);
23  * // => ''
24  *
25  * _.toString(-0);
26  * // => '-0'
27  *
28  * _.toString([1, 2, 3]);
29  * // => '1,2,3'
30  */
31 function toString(value) {
32   // Exit early for strings to avoid a performance hit in some environments.
33   if (typeof value == 'string') {
34     return value;
35   }
36   if (value == null) {
37     return '';
38   }
39   if (isSymbol(value)) {
40     return Symbol ? symbolToString.call(value) : '';
41   }
42   var result = (value + '');
43   return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
44 }
45
46 module.exports = toString;