index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. /** Used to match HTML entities and HTML characters. */
  14. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  15. reHasEscapedHtml = RegExp(reEscapedHtml.source);
  16. /** Used to map HTML entities to characters. */
  17. var htmlUnescapes = {
  18. '&amp;': '&',
  19. '&lt;': '<',
  20. '&gt;': '>',
  21. '&quot;': '"',
  22. '&#39;': "'",
  23. '&#96;': '`'
  24. };
  25. /** Detect free variable `global` from Node.js. */
  26. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  27. /** Detect free variable `self`. */
  28. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  29. /** Used as a reference to the global object. */
  30. var root = freeGlobal || freeSelf || Function('return this')();
  31. /**
  32. * The base implementation of `_.propertyOf` without support for deep paths.
  33. *
  34. * @private
  35. * @param {Object} object The object to query.
  36. * @returns {Function} Returns the new accessor function.
  37. */
  38. function basePropertyOf(object) {
  39. return function(key) {
  40. return object == null ? undefined : object[key];
  41. };
  42. }
  43. /**
  44. * Used by `_.unescape` to convert HTML entities to characters.
  45. *
  46. * @private
  47. * @param {string} chr The matched character to unescape.
  48. * @returns {string} Returns the unescaped character.
  49. */
  50. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  51. /** Used for built-in method references. */
  52. var objectProto = Object.prototype;
  53. /**
  54. * Used to resolve the
  55. * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  56. * of values.
  57. */
  58. var objectToString = objectProto.toString;
  59. /** Built-in value references. */
  60. var Symbol = root.Symbol;
  61. /** Used to convert symbols to primitives and strings. */
  62. var symbolProto = Symbol ? Symbol.prototype : undefined,
  63. symbolToString = symbolProto ? symbolProto.toString : undefined;
  64. /**
  65. * The base implementation of `_.toString` which doesn't convert nullish
  66. * values to empty strings.
  67. *
  68. * @private
  69. * @param {*} value The value to process.
  70. * @returns {string} Returns the string.
  71. */
  72. function baseToString(value) {
  73. // Exit early for strings to avoid a performance hit in some environments.
  74. if (typeof value == 'string') {
  75. return value;
  76. }
  77. if (isSymbol(value)) {
  78. return symbolToString ? symbolToString.call(value) : '';
  79. }
  80. var result = (value + '');
  81. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  82. }
  83. /**
  84. * Checks if `value` is object-like. A value is object-like if it's not `null`
  85. * and has a `typeof` result of "object".
  86. *
  87. * @static
  88. * @memberOf _
  89. * @since 4.0.0
  90. * @category Lang
  91. * @param {*} value The value to check.
  92. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  93. * @example
  94. *
  95. * _.isObjectLike({});
  96. * // => true
  97. *
  98. * _.isObjectLike([1, 2, 3]);
  99. * // => true
  100. *
  101. * _.isObjectLike(_.noop);
  102. * // => false
  103. *
  104. * _.isObjectLike(null);
  105. * // => false
  106. */
  107. function isObjectLike(value) {
  108. return !!value && typeof value == 'object';
  109. }
  110. /**
  111. * Checks if `value` is classified as a `Symbol` primitive or object.
  112. *
  113. * @static
  114. * @memberOf _
  115. * @since 4.0.0
  116. * @category Lang
  117. * @param {*} value The value to check.
  118. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  119. * @example
  120. *
  121. * _.isSymbol(Symbol.iterator);
  122. * // => true
  123. *
  124. * _.isSymbol('abc');
  125. * // => false
  126. */
  127. function isSymbol(value) {
  128. return typeof value == 'symbol' ||
  129. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  130. }
  131. /**
  132. * Converts `value` to a string. An empty string is returned for `null`
  133. * and `undefined` values. The sign of `-0` is preserved.
  134. *
  135. * @static
  136. * @memberOf _
  137. * @since 4.0.0
  138. * @category Lang
  139. * @param {*} value The value to process.
  140. * @returns {string} Returns the string.
  141. * @example
  142. *
  143. * _.toString(null);
  144. * // => ''
  145. *
  146. * _.toString(-0);
  147. * // => '-0'
  148. *
  149. * _.toString([1, 2, 3]);
  150. * // => '1,2,3'
  151. */
  152. function toString(value) {
  153. return value == null ? '' : baseToString(value);
  154. }
  155. /**
  156. * The inverse of `_.escape`; this method converts the HTML entities
  157. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to
  158. * their corresponding characters.
  159. *
  160. * **Note:** No other HTML entities are unescaped. To unescape additional
  161. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  162. *
  163. * @static
  164. * @memberOf _
  165. * @since 0.6.0
  166. * @category String
  167. * @param {string} [string=''] The string to unescape.
  168. * @returns {string} Returns the unescaped string.
  169. * @example
  170. *
  171. * _.unescape('fred, barney, &amp; pebbles');
  172. * // => 'fred, barney, & pebbles'
  173. */
  174. function unescape(string) {
  175. string = toString(string);
  176. return (string && reHasEscapedHtml.test(string))
  177. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  178. : string;
  179. }
  180. module.exports = unescape;