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.

ruleMessages.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. /**
  3. * Given an object of violation messages, return another
  4. * that provides the same messages postfixed with the rule
  5. * that has been violated.
  6. *
  7. * @param {string} ruleName
  8. * @param {{[k: string]: string|Function}} messages - Object whose keys are message identifiers
  9. * and values are either message strings or functions that return message strings
  10. * @return {{[k: string]: string|Function}} New message object, whose messages will be marked with the rule name
  11. */
  12. module.exports = function (ruleName, messages) {
  13. return Object.keys(messages).reduce(
  14. /**
  15. * @param {{[k: string]: string|Function}} newMessages
  16. * @param {string} messageId
  17. * @return {{[k: string]: string|Function}}
  18. */
  19. (newMessages, messageId) => {
  20. const messageText = messages[messageId];
  21. if (typeof messageText === 'string') {
  22. newMessages[messageId] = `${messageText} (${ruleName})`;
  23. } else {
  24. newMessages[messageId] = (/** @type {any[]} */ ...args) => {
  25. return `${messageText(...args)} (${ruleName})`;
  26. };
  27. }
  28. return newMessages;
  29. },
  30. {},
  31. );
  32. };