Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

_baseToString.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  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;