deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

feat request: add a pluralize word function

Open lowlighter opened this issue 1 year ago • 4 comments

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 has around 7-8 millions weekly download and around 3 millions dependant 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 in std

Describe alternatives you've considered

Using either the npm pluralize package or a custom function (not ideal) like

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`
}

lowlighter avatar Jul 12 '24 04:07 lowlighter