_baseToString.js 934 B

12345678910111213141516171819202122232425262728293031
  1. var Symbol = require('./_Symbol'),
  2. isSymbol = require('./isSymbol');
  3. /** Used as references for various `Number` constants. */
  4. var INFINITY = 1 / 0;
  5. /** Used to convert symbols to primitives and strings. */
  6. var symbolProto = Symbol ? Symbol.prototype : undefined,
  7. symbolToString = symbolProto ? symbolProto.toString : undefined;
  8. /**
  9. * The base implementation of `_.toString` which doesn't convert nullish
  10. * values to empty strings.
  11. *
  12. * @private
  13. * @param {*} value The value to process.
  14. * @returns {string} Returns the string.
  15. */
  16. function baseToString(value) {
  17. // Exit early for strings to avoid a performance hit in some environments.
  18. if (typeof value == 'string') {
  19. return value;
  20. }
  21. if (isSymbol(value)) {
  22. return symbolToString ? symbolToString.call(value) : '';
  23. }
  24. var result = (value + '');
  25. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  26. }
  27. module.exports = baseToString;