27 ms·
“There are 1 item(s) in your cart.”
- byoung2 7y agoThere are also libraries to handle this, like https://github.com/blakeembrey/pluralize https://github.com/blakeembrey/pluralize that does only this, or my own https://github.com/byoung2/grandiloquent https://github.com/byoung2/grandiloquent that can pluralize, in addition to a lot of other things. Here is an example from Grandiloquent: let quantity = 5; let sentence = grandiloquent .sentence(`${ quantity } item added to cart`); if(quantity !== 1) { sentence.transform('$subject', 'toPlural'); } console.log(sentence.toString()); //5 items added to cart.