Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

node.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /**
  2. * Module dependencies.
  3. */
  4. const tty = require('tty');
  5. const util = require('util');
  6. /**
  7. * This is the Node.js implementation of `debug()`.
  8. */
  9. exports.init = init;
  10. exports.log = log;
  11. exports.formatArgs = formatArgs;
  12. exports.save = save;
  13. exports.load = load;
  14. exports.useColors = useColors;
  15. exports.destroy = util.deprecate(
  16. () => {},
  17. 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
  18. );
  19. /**
  20. * Colors.
  21. */
  22. exports.colors = [6, 2, 3, 4, 5, 1];
  23. try {
  24. // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
  25. // eslint-disable-next-line import/no-extraneous-dependencies
  26. const supportsColor = require('supports-color');
  27. if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
  28. exports.colors = [
  29. 20,
  30. 21,
  31. 26,
  32. 27,
  33. 32,
  34. 33,
  35. 38,
  36. 39,
  37. 40,
  38. 41,
  39. 42,
  40. 43,
  41. 44,
  42. 45,
  43. 56,
  44. 57,
  45. 62,
  46. 63,
  47. 68,
  48. 69,
  49. 74,
  50. 75,
  51. 76,
  52. 77,
  53. 78,
  54. 79,
  55. 80,
  56. 81,
  57. 92,
  58. 93,
  59. 98,
  60. 99,
  61. 112,
  62. 113,
  63. 128,
  64. 129,
  65. 134,
  66. 135,
  67. 148,
  68. 149,
  69. 160,
  70. 161,
  71. 162,
  72. 163,
  73. 164,
  74. 165,
  75. 166,
  76. 167,
  77. 168,
  78. 169,
  79. 170,
  80. 171,
  81. 172,
  82. 173,
  83. 178,
  84. 179,
  85. 184,
  86. 185,
  87. 196,
  88. 197,
  89. 198,
  90. 199,
  91. 200,
  92. 201,
  93. 202,
  94. 203,
  95. 204,
  96. 205,
  97. 206,
  98. 207,
  99. 208,
  100. 209,
  101. 214,
  102. 215,
  103. 220,
  104. 221
  105. ];
  106. }
  107. } catch (error) {
  108. // Swallow - we only care if `supports-color` is available; it doesn't have to be.
  109. }
  110. /**
  111. * Build up the default `inspectOpts` object from the environment variables.
  112. *
  113. * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
  114. */
  115. exports.inspectOpts = Object.keys(process.env).filter(key => {
  116. return /^debug_/i.test(key);
  117. }).reduce((obj, key) => {
  118. // Camel-case
  119. const prop = key
  120. .substring(6)
  121. .toLowerCase()
  122. .replace(/_([a-z])/g, (_, k) => {
  123. return k.toUpperCase();
  124. });
  125. // Coerce string value into JS value
  126. let val = process.env[key];
  127. if (/^(yes|on|true|enabled)$/i.test(val)) {
  128. val = true;
  129. } else if (/^(no|off|false|disabled)$/i.test(val)) {
  130. val = false;
  131. } else if (val === 'null') {
  132. val = null;
  133. } else {
  134. val = Number(val);
  135. }
  136. obj[prop] = val;
  137. return obj;
  138. }, {});
  139. /**
  140. * Is stdout a TTY? Colored output is enabled when `true`.
  141. */
  142. function useColors() {
  143. return 'colors' in exports.inspectOpts ?
  144. Boolean(exports.inspectOpts.colors) :
  145. tty.isatty(process.stderr.fd);
  146. }
  147. /**
  148. * Adds ANSI color escape codes if enabled.
  149. *
  150. * @api public
  151. */
  152. function formatArgs(args) {
  153. const {namespace: name, useColors} = this;
  154. if (useColors) {
  155. const c = this.color;
  156. const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
  157. const prefix = ` ${colorCode};1m${name} \u001B[0m`;
  158. args[0] = prefix + args[0].split('\n').join('\n' + prefix);
  159. args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
  160. } else {
  161. args[0] = getDate() + name + ' ' + args[0];
  162. }
  163. }
  164. function getDate() {
  165. if (exports.inspectOpts.hideDate) {
  166. return '';
  167. }
  168. return new Date().toISOString() + ' ';
  169. }
  170. /**
  171. * Invokes `util.format()` with the specified arguments and writes to stderr.
  172. */
  173. function log(...args) {
  174. return process.stderr.write(util.format(...args) + '\n');
  175. }
  176. /**
  177. * Save `namespaces`.
  178. *
  179. * @param {String} namespaces
  180. * @api private
  181. */
  182. function save(namespaces) {
  183. if (namespaces) {
  184. process.env.DEBUG = namespaces;
  185. } else {
  186. // If you set a process.env field to null or undefined, it gets cast to the
  187. // string 'null' or 'undefined'. Just delete instead.
  188. delete process.env.DEBUG;
  189. }
  190. }
  191. /**
  192. * Load `namespaces`.
  193. *
  194. * @return {String} returns the previously persisted debug modes
  195. * @api private
  196. */
  197. function load() {
  198. return process.env.DEBUG;
  199. }
  200. /**
  201. * Init logic for `debug` instances.
  202. *
  203. * Create a new `inspectOpts` object in case `useColors` is set
  204. * differently for a particular `debug` instance.
  205. */
  206. function init(debug) {
  207. debug.inspectOpts = {};
  208. const keys = Object.keys(exports.inspectOpts);
  209. for (let i = 0; i < keys.length; i++) {
  210. debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
  211. }
  212. }
  213. module.exports = require('./common')(exports);
  214. const {formatters} = module.exports;
  215. /**
  216. * Map %o to `util.inspect()`, all on a single line.
  217. */
  218. formatters.o = function (v) {
  219. this.inspectOpts.colors = this.useColors;
  220. return util.inspect(v, this.inspectOpts)
  221. .split('\n')
  222. .map(str => str.trim())
  223. .join(' ');
  224. };
  225. /**
  226. * Map %O to `util.inspect()`, allowing multiple lines if needed.
  227. */
  228. formatters.O = function (v) {
  229. this.inspectOpts.colors = this.useColors;
  230. return util.inspect(v, this.inspectOpts);
  231. };