appendRuleName.mjs 548 B

12345678910111213
  1. /**
  2. * Ensures the given rule name is appended to the provided string.
  3. *
  4. * If the string does not already end with the rule name in parentheses, the rule name is appended in parentheses.
  5. *
  6. * @param {string} string - The message to which the rule name may be appended
  7. * @param {string} ruleName - The rule name to append
  8. *
  9. * @returns {string} The provided string with the given rule name appended
  10. */
  11. export default function appendRuleName(string, ruleName) {
  12. return !string.endsWith(`(${ruleName})`) ? `${string} (${ruleName})` : string;
  13. }