All files / utils chatCooldownUtils.js

100% Statements 10/10
100% Branches 6/6
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1813x     9x 9x 9x 3x   6x 2x   4x       2x    
const plural = (count, unit) => `${count} ${unit}${count === 1 ? "" : "s"}`;
 
export function formatCooldownRemaining(totalSeconds) {
  const minutes = Math.floor(totalSeconds / 60);
  const seconds = totalSeconds % 60;
  if (minutes === 0) {
    return plural(seconds, "second");
  }
  if (seconds === 0) {
    return plural(minutes, "minute");
  }
  return `${plural(minutes, "minute")} ${plural(seconds, "second")}`;
}
 
export function cooldownErrorMessage(totalSeconds) {
  return `You are on a chat cooldown. You can send messages again in ${formatCooldownRemaining(totalSeconds)}.`;
}