mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
15 lines
578 B
TypeScript
15 lines
578 B
TypeScript
/**
|
|
* Given a toast message, calculate the ideal timeout length following:
|
|
* a minimum of 5 seconds + 1 extra second per 120 additional words
|
|
*
|
|
* @param message the toast message to be displayed
|
|
* @returns the timeout length in milliseconds
|
|
*/
|
|
export const calculateToastTimeout = (message: string | string[]): number => {
|
|
const paragraphs = Array.isArray(message) ? message : [message];
|
|
const numWords = paragraphs
|
|
.map((paragraph) => paragraph.split(/\s+/).filter((word) => word !== ""))
|
|
.flat().length;
|
|
return 5000 + Math.floor(numWords / 120) * 1000;
|
|
};
|