Hacker News new | past | comments | ask | show | jobs | submit login
“There are 1 item(s) in your cart.” (number.fyi)
3 points by newbold 4 days ago | hide | past | web | favorite | 1 comment





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.



Applications are open for YC Summer 2020

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: