index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  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
  8. */
  9. /** Used as references for various `Number` constants. */
  10. var INFINITY = 1 / 0;
  11. /** `Object#toString` result references. */
  12. var symbolTag = '[object Symbol]';
  13. /** Detect free variable `global` from Node.js. */
  14. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  15. /** Detect free variable `self`. */
  16. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  17. /** Used as a reference to the global object. */
  18. var root = freeGlobal || freeSelf || Function('return this')();
  19. /** Used for built-in method references. */
  20. var objectProto = Object.prototype;
  21. /**
  22. * Used to resolve the
  23. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  24. * of values.
  25. */
  26. var objectToString = objectProto.toString;
  27. /** Built-in value references. */
  28. var Symbol = root.Symbol;
  29. /** Used to convert symbols to primitives and strings. */
  30. var symbolProto = Symbol ? Symbol.prototype : undefined,
  31. symbolToString = symbolProto ? symbolProto.toString : undefined;
  32. /**
  33. * The base implementation of `_.toString` which doesn't convert nullish
  34. * values to empty strings.
  35. *
  36. * @private
  37. * @param {*} value The value to process.
  38. * @returns {string} Returns the string.
  39. */
  40. function baseToString(value) {
  41. // Exit early for strings to avoid a performance hit in some environments.
  42. if (typeof value == 'string') {
  43. return value;
  44. }
  45. if (isSymbol(value)) {
  46. return symbolToString ? symbolToString.call(value) : '';
  47. }
  48. var result = (value + '');
  49. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  50. }
  51. /**
  52. * Checks if `value` is object-like. A value is object-like if it's not `null`
  53. * and has a `typeof` result of "object".
  54. *
  55. * @static
  56. * @memberOf _
  57. * @since 4.0.0
  58. * @category Lang
  59. * @param {*} value The value to check.
  60. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  61. * @example
  62. *
  63. * _.isObjectLike({});
  64. * // => true
  65. *
  66. * _.isObjectLike([1, 2, 3]);
  67. * // => true
  68. *
  69. * _.isObjectLike(_.noop);
  70. * // => false
  71. *
  72. * _.isObjectLike(null);
  73. * // => false
  74. */
  75. function isObjectLike(value) {
  76. return !!value && typeof value == 'object';
  77. }
  78. /**
  79. * Checks if `value` is classified as a `Symbol` primitive or object.
  80. *
  81. * @static
  82. * @memberOf _
  83. * @since 4.0.0
  84. * @category Lang
  85. * @param {*} value The value to check.
  86. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  87. * @example
  88. *
  89. * _.isSymbol(Symbol.iterator);
  90. * // => true
  91. *
  92. * _.isSymbol('abc');
  93. * // => false
  94. */
  95. function isSymbol(value) {
  96. return typeof value == 'symbol' ||
  97. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  98. }
  99. /**
  100. * Converts `value` to a string. An empty string is returned for `null`
  101. * and `undefined` values. The sign of `-0` is preserved.
  102. *
  103. * @static
  104. * @memberOf _
  105. * @since 4.0.0
  106. * @category Lang
  107. * @param {*} value The value to process.
  108. * @returns {string} Returns the string.
  109. * @example
  110. *
  111. * _.toString(null);
  112. * // => ''
  113. *
  114. * _.toString(-0);
  115. * // => '-0'
  116. *
  117. * _.toString([1, 2, 3]);
  118. * // => '1,2,3'
  119. */
  120. function toString(value) {
  121. return value == null ? '' : baseToString(value);
  122. }
  123. module.exports = toString;