You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

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