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

272 lines
5.9 KiB

6 months ago
2 months ago
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. // eslint-disable-next-line no-return-assign
  123. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  124. // Is firebug? http://stackoverflow.com/a/398120/376773
  125. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  126. // Is firefox >= v31?
  127. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  128. (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
  129. // Double check webkit in userAgent just in case we are in a worker
  130. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  131. }
  132. /**
  133. * Colorize log arguments if enabled.
  134. *
  135. * @api public
  136. */
  137. function formatArgs(args) {
  138. args[0] = (this.useColors ? '%c' : '') +
  139. this.namespace +
  140. (this.useColors ? ' %c' : ' ') +
  141. args[0] +
  142. (this.useColors ? '%c ' : ' ') +
  143. '+' + module.exports.humanize(this.diff);
  144. if (!this.useColors) {
  145. return;
  146. }
  147. const c = 'color: ' + this.color;
  148. args.splice(1, 0, c, 'color: inherit');
  149. // The final "%c" is somewhat tricky, because there could be other
  150. // arguments passed either before or after the %c, so we need to
  151. // figure out the correct index to insert the CSS into
  152. let index = 0;
  153. let lastC = 0;
  154. args[0].replace(/%[a-zA-Z%]/g, match => {
  155. if (match === '%%') {
  156. return;
  157. }
  158. index++;
  159. if (match === '%c') {
  160. // We only are interested in the *last* %c
  161. // (the user may have provided their own)
  162. lastC = index;
  163. }
  164. });
  165. args.splice(lastC, 0, c);
  166. }
  167. /**
  168. * Invokes `console.debug()` when available.
  169. * No-op when `console.debug` is not a "function".
  170. * If `console.debug` is not available, falls back
  171. * to `console.log`.
  172. *
  173. * @api public
  174. */
  175. exports.log = console.debug || console.log || (() => {});
  176. /**
  177. * Save `namespaces`.
  178. *
  179. * @param {String} namespaces
  180. * @api private
  181. */
  182. function save(namespaces) {
  183. try {
  184. if (namespaces) {
  185. exports.storage.setItem('debug', namespaces);
  186. } else {
  187. exports.storage.removeItem('debug');
  188. }
  189. } catch (error) {
  190. // Swallow
  191. // XXX (@Qix-) should we be logging these?
  192. }
  193. }
  194. /**
  195. * Load `namespaces`.
  196. *
  197. * @return {String} returns the previously persisted debug modes
  198. * @api private
  199. */
  200. function load() {
  201. let r;
  202. try {
  203. r = exports.storage.getItem('debug');
  204. } catch (error) {
  205. // Swallow
  206. // XXX (@Qix-) should we be logging these?
  207. }
  208. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  209. if (!r && typeof process !== 'undefined' && 'env' in process) {
  210. r = process.env.DEBUG;
  211. }
  212. return r;
  213. }
  214. /**
  215. * Localstorage attempts to return the localstorage.
  216. *
  217. * This is necessary because safari throws
  218. * when a user disables cookies/localstorage
  219. * and you attempt to access it.
  220. *
  221. * @return {LocalStorage}
  222. * @api private
  223. */
  224. function localstorage() {
  225. try {
  226. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  227. // The Browser also has localStorage in the global context.
  228. return localStorage;
  229. } catch (error) {
  230. // Swallow
  231. // XXX (@Qix-) should we be logging these?
  232. }
  233. }
  234. module.exports = require('./common')(exports);
  235. const {formatters} = module.exports;
  236. /**
  237. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  238. */
  239. formatters.j = function (v) {
  240. try {
  241. return JSON.stringify(v);
  242. } catch (error) {
  243. return '[UnexpectedJSONParseError]: ' + error.message;
  244. }
  245. };