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.

utils.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.createDidYouMeanMessage =
  6. exports.logValidationWarning =
  7. exports.ValidationError =
  8. exports.formatPrettyObject =
  9. exports.format =
  10. exports.WARNING =
  11. exports.ERROR =
  12. exports.DEPRECATION =
  13. void 0;
  14. function _chalk() {
  15. const data = _interopRequireDefault(require('chalk'));
  16. _chalk = function () {
  17. return data;
  18. };
  19. return data;
  20. }
  21. function _leven() {
  22. const data = _interopRequireDefault(require('leven'));
  23. _leven = function () {
  24. return data;
  25. };
  26. return data;
  27. }
  28. function _prettyFormat() {
  29. const data = require('pretty-format');
  30. _prettyFormat = function () {
  31. return data;
  32. };
  33. return data;
  34. }
  35. function _interopRequireDefault(obj) {
  36. return obj && obj.__esModule ? obj : {default: obj};
  37. }
  38. function _defineProperty(obj, key, value) {
  39. if (key in obj) {
  40. Object.defineProperty(obj, key, {
  41. value: value,
  42. enumerable: true,
  43. configurable: true,
  44. writable: true
  45. });
  46. } else {
  47. obj[key] = value;
  48. }
  49. return obj;
  50. }
  51. const BULLET = _chalk().default.bold('\u25cf');
  52. const DEPRECATION = `${BULLET} Deprecation Warning`;
  53. exports.DEPRECATION = DEPRECATION;
  54. const ERROR = `${BULLET} Validation Error`;
  55. exports.ERROR = ERROR;
  56. const WARNING = `${BULLET} Validation Warning`;
  57. exports.WARNING = WARNING;
  58. const format = value =>
  59. typeof value === 'function'
  60. ? value.toString()
  61. : (0, _prettyFormat().format)(value, {
  62. min: true
  63. });
  64. exports.format = format;
  65. const formatPrettyObject = value =>
  66. typeof value === 'function'
  67. ? value.toString()
  68. : JSON.stringify(value, null, 2).split('\n').join('\n ');
  69. exports.formatPrettyObject = formatPrettyObject;
  70. class ValidationError extends Error {
  71. constructor(name, message, comment) {
  72. super();
  73. _defineProperty(this, 'name', void 0);
  74. _defineProperty(this, 'message', void 0);
  75. comment = comment ? '\n\n' + comment : '\n';
  76. this.name = '';
  77. this.message = _chalk().default.red(
  78. _chalk().default.bold(name) + ':\n\n' + message + comment
  79. );
  80. Error.captureStackTrace(this, () => {});
  81. }
  82. }
  83. exports.ValidationError = ValidationError;
  84. const logValidationWarning = (name, message, comment) => {
  85. comment = comment ? '\n\n' + comment : '\n';
  86. console.warn(
  87. _chalk().default.yellow(
  88. _chalk().default.bold(name) + ':\n\n' + message + comment
  89. )
  90. );
  91. };
  92. exports.logValidationWarning = logValidationWarning;
  93. const createDidYouMeanMessage = (unrecognized, allowedOptions) => {
  94. const suggestion = allowedOptions.find(option => {
  95. const steps = (0, _leven().default)(option, unrecognized);
  96. return steps < 3;
  97. });
  98. return suggestion
  99. ? `Did you mean ${_chalk().default.bold(format(suggestion))}?`
  100. : '';
  101. };
  102. exports.createDidYouMeanMessage = createDidYouMeanMessage;