1
Fork 0

Add a pluralize utility function.

This commit is contained in:
Bauke 2023-06-29 23:24:20 +02:00
parent 35f1bf35ca
commit 0fff485473
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 19 additions and 0 deletions

View File

@ -6,4 +6,5 @@ export * from "./groups.js";
export * from "./logging.js"; export * from "./logging.js";
export * from "./query-selectors.js"; export * from "./query-selectors.js";
export * from "./report-a-bug.js"; export * from "./report-a-bug.js";
export * from "./text.js";
export * from "./validators.js"; export * from "./validators.js";

18
source/utilities/text.ts Normal file
View File

@ -0,0 +1,18 @@
/**
* Pluralize a word based on a count.
* @param count The number of things.
* @param singular The word in its singular form.
* @param plural Optionally the word in its plural form. If left undefined the
* returned string will be the singular form plus the letter "s".
*/
export function pluralize(
count: number,
singular: string,
plural?: string,
): string {
if (count === 1) {
return singular;
}
return plural ?? singular + "s";
}