New manipulation method: pluralise
DJTB opened this issue · 2 comments
Hey there! I've been using voca heavily in an app, however I had to create a plural function for a few places that voca couldn't help with. Since it's a simple helper and seemed to fit in with the other manipulation methods like capitalise() I thought it might be worthy addition to the library.
Pluralises strings, given a subject and an amount.
Also takes an optional plural string for deviations/uncommon plurals.
v.pluralise('dog', 0);
// => 'dogs'
v.pluralise('dog', 1);
// => 'dog'
v.pluralise('dog', 2);
// => 'dogs'
v.pluralise('dog', -4);
// => 'dogs'
v.pluralise('wolf', 1, 'wolves');
// => 'wolf'
v.pluralise('wolf', 42, 'wolves');
// => 'wolves'
Check List
- [:heavy_check_mark:] All tests passed
- [:heavy_check_mark:] Added tests to ensure correctness
- [:heavy_check_mark:] Added jsdoc annotations
Can view the changes here if you'd like me to make a proper PR.
https://github.com/DJTB/voca/commit/0ee27311feca765711cb30bc008d29032cc44829
Hi @DJTB,
Thank you for the idea.
While the function indeed is helpful in some situations, it solves a very specific problem. I design the library as a standard tool for manipulating strings, without diving into solving edge situations.
It prevents the library from having an excessive number of functions that are really rarely used.
If someone needs to pluralize the string, it's better to choose a specific library that solves this problem. For instance https://github.com/jeremyruppel/underscore.inflection.
Thanks for your time!
No problem, I understand wanting to keep the api surface small. I wasn't aware of inflection, just what I was after!