Quantcast
Channel: Design Bit
Viewing all articles
Browse latest Browse all 38

Pluralizing strings in Javascript ES6.

$
0
0

Have you ever wondered: How can I pluralize words in Javascript?

Wonder no more!

You can use the pluralize library for this.

NPM:
npm install pluralize --save
Yarn:
yarn add pluralize

Wherever you want to use the lib, you can require it easily.

var pluralize = require('pluralize')

I like to add it to the window object so I can just invoke pluralize() wherever I need it. Within my application.js root file:

window.pluralize = require('pluralize')

Then you can just use it anywhere.

<span className="pull-left">
{`${item.score} ${pluralize('point', item.score)}`}
</span>

You can find the pluralize library here:

blakeembrey/pluralize


Pluralizing strings in Javascript ES6. was originally published in sergiotapia on Medium, where people are continuing the conversation by highlighting and responding to this story.


Viewing all articles
Browse latest Browse all 38

Trending Articles