租房小程序前端代码
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.

271 lines
5.9 KiB

6 months ago
  1. /* eslint-env browser */
  2. /**
  3. * This is the web browser implementation of `debug()`.
  4. */
  5. exports.formatArgs = formatArgs;
  6. exports.save = save;
  7. exports.load = load;
  8. exports.useColors = useColors;
  9. exports.storage = localstorage();
  10. exports.destroy = (() => {
  11. let warned = false;
  12. return () => {
  13. if (!warned) {
  14. warned = true;
  15. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  16. }
  17. };
  18. })();
  19. /**
  20. * Colors.
  21. */
  22. exports.colors = [
  23. '#0000CC',
  24. '#0000FF',
  25. '#0033CC',
  26. '#0033FF',
  27. '#0066CC',
  28. '#0066FF',
  29. '#0099CC',
  30. '#0099FF',
  31. '#00CC00',
  32. '#00CC33',
  33. '#00CC66',
  34. '#00CC99',
  35. '#00CCCC',
  36. '#00CCFF',
  37. '#3300CC',
  38. '#3300FF',
  39. '#3333CC',
  40. '#3333FF',
  41. '#3366CC',
  42. '#3366FF',
  43. '#3399CC',
  44. '#3399FF',
  45. '#33CC00',
  46. '#33CC33',
  47. '#33CC66',
  48. '#33CC99',
  49. '#33CCCC',
  50. '#33CCFF',
  51. '#6600CC',
  52. '#6600FF',
  53. '#6633CC',
  54. '#6633FF',
  55. '#66CC00',
  56. '#66CC33',
  57. '#9900CC',
  58. '#9900FF',
  59. '#9933CC',
  60. '#9933FF',
  61. '#99CC00',
  62. '#99CC33',
  63. '#CC0000',
  64. '#CC0033',
  65. '#CC0066',
  66. '#CC0099',
  67. '#CC00CC',
  68. '#CC00FF',
  69. '#CC3300',
  70. '#CC3333',
  71. '#CC3366',
  72. '#CC3399',
  73. '#CC33CC',
  74. '#CC33FF',
  75. '#CC6600',
  76. '#CC6633',
  77. '#CC9900',
  78. '#CC9933',
  79. '#CCCC00',
  80. '#CCCC33',
  81. '#FF0000',
  82. '#FF0033',
  83. '#FF0066',
  84. '#FF0099',
  85. '#FF00CC',
  86. '#FF00FF',
  87. '#FF3300',
  88. '#FF3333',
  89. '#FF3366',
  90. '#FF3399',
  91. '#FF33CC',
  92. '#FF33FF',
  93. '#FF6600',
  94. '#FF6633',
  95. '#FF9900',
  96. '#FF9933',
  97. '#FFCC00',
  98. '#FFCC33'
  99. ];
  100. /**
  101. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  102. * and the Firebug extension (any Firefox version) are known
  103. * to support "%c" CSS customizations.
  104. *
  105. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  106. */
  107. // eslint-disable-next-line complexity
  108. function useColors() {
  109. // NB: In an Electron preload script, document will be defined but not fully
  110. // initialized. Since we know we're in Chrome, we'll just detect this case
  111. // explicitly
  112. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  113. return true;
  114. }
  115. // Internet Explorer and Edge do not support colors.
  116. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  117. return false;
  118. }
  119. let m;
  120. // Is webkit? http://stackoverflow.com/a/16459606/376773
  121. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  122. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  123. // Is firebug? http://stackoverflow.com/a/398120/376773
  124. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  125. // Is firefox >= v31?
  126. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  127. (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
  128. // Double check webkit in userAgent just in case we are in a worker
  129. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  130. }
  131. /**
  132. * Colorize log arguments if enabled.
  133. *
  134. * @api public
  135. */
  136. function formatArgs(args) {
  137. args[0] = (this.useColors ? '%c' : '') +
  138. this.namespace +
  139. (this.useColors ? ' %c' : ' ') +
  140. args[0] +
  141. (this.useColors ? '%c ' : ' ') +
  142. '+' + module.exports.humanize(this.diff);
  143. if (!this.useColors) {
  144. return;
  145. }
  146. const c = 'color: ' + this.color;
  147. args.splice(1, 0, c, 'color: inherit');
  148. // The final "%c" is somewhat tricky, because there could be other
  149. // arguments passed either before or after the %c, so we need to
  150. // figure out the correct index to insert the CSS into
  151. let index = 0;
  152. let lastC = 0;
  153. args[0].replace(/%[a-zA-Z%]/g, match => {
  154. if (match === '%%') {
  155. return;
  156. }
  157. index++;
  158. if (match === '%c') {
  159. // We only are interested in the *last* %c
  160. // (the user may have provided their own)
  161. lastC = index;
  162. }
  163. });
  164. args.splice(lastC, 0, c);
  165. }
  166. /**
  167. * Invokes `console.debug()` when available.
  168. * No-op when `console.debug` is not a "function".
  169. * If `console.debug` is not available, falls back
  170. * to `console.log`.
  171. *
  172. * @api public
  173. */
  174. exports.log = console.debug || console.log || (() => {});
  175. /**
  176. * Save `namespaces`.
  177. *
  178. * @param {String} namespaces
  179. * @api private
  180. */
  181. function save(namespaces) {
  182. try {
  183. if (namespaces) {
  184. exports.storage.setItem('debug', namespaces);
  185. } else {
  186. exports.storage.removeItem('debug');
  187. }
  188. } catch (error) {
  189. // Swallow
  190. // XXX (@Qix-) should we be logging these?
  191. }
  192. }
  193. /**
  194. * Load `namespaces`.
  195. *
  196. * @return {String} returns the previously persisted debug modes
  197. * @api private
  198. */
  199. function load() {
  200. let r;
  201. try {
  202. r = exports.storage.getItem('debug');
  203. } catch (error) {
  204. // Swallow
  205. // XXX (@Qix-) should we be logging these?
  206. }
  207. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  208. if (!r && typeof process !== 'undefined' && 'env' in process) {
  209. r = process.env.DEBUG;
  210. }
  211. return r;
  212. }
  213. /**
  214. * Localstorage attempts to return the localstorage.
  215. *
  216. * This is necessary because safari throws
  217. * when a user disables cookies/localstorage
  218. * and you attempt to access it.
  219. *
  220. * @return {LocalStorage}
  221. * @api private
  222. */
  223. function localstorage() {
  224. try {
  225. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  226. // The Browser also has localStorage in the global context.
  227. return localStorage;
  228. } catch (error) {
  229. // Swallow
  230. // XXX (@Qix-) should we be logging these?
  231. }
  232. }
  233. module.exports = require('./common')(exports);
  234. const {formatters} = module.exports;
  235. /**
  236. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  237. */
  238. formatters.j = function (v) {
  239. try {
  240. return JSON.stringify(v);
  241. } catch (error) {
  242. return '[UnexpectedJSONParseError]: ' + error.message;
  243. }
  244. };