feat request: add a pluralize word function
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Pluralizing english words is useful for many things:
- Map more easily codebase with collections, database tables, etc.
- e.g. `class Item {}` => `/api/items`
- e.g. `class Item {}` => `INSERT INTO items VALUES ...`
- Tooling written in english
- e.g. Polished text using correct pluralization when 0, 1 or N elements, etc.
- ...
The [`pluralize`](https://www.npmjs.com/package/pluralize) has around 7-8 millions weekly download and around [3 millions dependant](https://github.com/plurals/pluralize/network/dependents?dependents_after=Mzk4MDc2NjcyNjk) on GitHub
The mentionned package also support singularization, which could be also useful to map back stuff, although it might be less used.
**Describe the solution you'd like**
Something similar to [`pluralize`](https://www.npmjs.com/package/pluralize) in std
**Describe alternatives you've considered**
Using either the npm `pluralize` package or a custom function (not ideal) like
```ts
function pluralize(word: string) {
if (/(?:s|x|ch|sh)$/.test(word)) {
return `${word}es`
}
if (/(?:[^aeiou])y$/.test(word)) {
return `${word.slice(0, -1)}ies`
}
if (/o$/.test(word)) {
return `${word}es`
}
if (/f$/.test(word)) {
return `${word.slice(0, -1)}ves`
}
return `${word}s`
}
Contributor guide
Assessment
This issue has not been assessed yet.