utils/ts-src/maybePluralize.ts
Martin Donnelly c30b36b3f6 init
2020-11-17 11:16:34 +00:00

19 lines
481 B
TypeScript

/**
* Maybe pluralize a count:
*
* @param count the value counting
* @param noun the name of the value
* @param suffix the suffix
* @returns {string}
*
* @signature
* U.maybePluralize(number, noun, suffix)
*
* @example
* U.maybePluralize(1, 'Bag', 's') // => 1 Bag
* U.maybePluralize(5, 'Bag', 's') // => 5 Bags
*/
export function maybePluralize(count: number, noun: string, suffix = 's'): string {
return `${count} ${noun}${count !== 1 ? suffix : ''}`;
}