(text: string, amount?: number)
| 22 | } |
| 23 | |
| 24 | export function pluralize(text: string, amount?: number): string { |
| 25 | if (amount != null && Math.abs(amount) === 1) { |
| 26 | return text; |
| 27 | } |
| 28 | |
| 29 | // best approximation of English pluralization "rules" |
| 30 | // https://www.grammarly.com/blog/grammar/spelling-plurals-with-s-es/ |
| 31 | |
| 32 | if (text.endsWith('y')) { |
| 33 | return `${text.slice(0, -1)}ies`; |
| 34 | } |
| 35 | const suffixes = ['s', 'sh', 'ch', 'x', 'z']; |
| 36 | if (suffixes.some(suffix => text.endsWith(suffix))) { |
| 37 | return `${text}es`; |
| 38 | } |
| 39 | return `${text}s`; |
| 40 | } |
| 41 | |
| 42 | export function formatBytes(bytes: number, decimals = 2) { |
| 43 | const positiveBytes = Math.max(bytes, 0); |
no outgoing calls
no test coverage detected