News for hackers. Stuff that matters.
Re:“There are 1 item(s) in your cart.” by byoung2 on Friday February 14, 2020 @02:10AM (#22324579)
There are also libraries to handle this, like https://github.com/blakeembrey/pluralize that does only this, or my own 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.

There are no comments on this comment yet.