Looking for shorthand
Answered
Japanese Bobtail posted this in #help-forum
Japanese BobtailOP
Hello there. I'am looking for a shorthand with condition:
If only 1 article, there's no need for the "s" in articles. In other words add "s" to article if count is greater 1.
If only 1 article, there's no need for the "s" in articles. In other words add "s" to article if count is greater 1.
aria-label={
Category ${name.replace('&', '&')} with ${count} articles}
Answered by B33fb0n3
you can use packages like [pluralize](https://www.npmjs.com/package/pluralize) to do this for you.
The syntax is easy:
And it's used by many others as well (see attached)
The syntax is easy:
pluralize('test') //=> "tests"
pluralize('test', 0) //=> "tests"
pluralize('test', 1) //=> "test"
pluralize('test', 5) //=> "tests"
pluralize('test', 1, true) //=> "1 test"
pluralize('test', 5, true) //=> "5 tests"
And it's used by many others as well (see attached)
9 Replies
you can use packages like [pluralize](https://www.npmjs.com/package/pluralize) to do this for you.
The syntax is easy:
And it's used by many others as well (see attached)
The syntax is easy:
pluralize('test') //=> "tests"
pluralize('test', 0) //=> "tests"
pluralize('test', 1) //=> "test"
pluralize('test', 5) //=> "tests"
pluralize('test', 1, true) //=> "1 test"
pluralize('test', 5, true) //=> "5 tests"
And it's used by many others as well (see attached)
Answer
Japanese BobtailOP
That's fine for more than one condition. But in my opinion thats better:
aria-label={Category ${name.replace('&', '&')} with ${count} article${count !== 1 ? 's' : ''}}
of course there are multiple versions on how you can solve a problem.
I like to use:
Instead of doing
I like to use:
pluralize('article', 2, true)
Instead of doing
aria-label={${count} article${count !== 1 ? 's' : ''}}
Japanese BobtailOP
Is it possible to shorthand
${count !== 1 ? 's' : ''}
we do not need the else.for some words the plural isn't just an "s" at the end. So no, not with this package
Japanese BobtailOP
ok i will keep the plugin in mind. thanks for help sir.
sure thing, is your initial question resolved like that?
Japanese BobtailOP
yes
happy to help