plurals / pluralize

Pluralize or singularize any word based on a count
MIT License
2.15k stars 184 forks source link

Abbreviated words #49

Open daut opened 7 years ago

daut commented 7 years ago

Hey,

I'm currently working on a project that needs to support pluralization of the abbreviated words, so I need to add lowercase 's' letter to the end of these words (e.g. VIP => VIPs, currently I get VIPS).

Are you planning to add this feature to your library? Something like pluralize.addAbbreviatedRule() or similar.

Regards

P.S. Thanks for the great library!

blakeembrey commented 7 years ago

I thought there had been a previous discussion around this sort of thing, but I can't recall it now. I think it's reasonable to want to do this, but in reality I'd need to know a lot more about the context to figure out if it's something that should be here. Can you give more information? An abbreviated rule is pretty similar to an irregular rule, what would be the main difference? Is it just how to handle casing, in which case is there perhaps a better way (maybe a case-sensitivity flag?) that doesn't change the core behaviour?

daut commented 7 years ago

Yes, In my use case only difference between an abbreviated rule and irregular rule is case handling. So something like addIrregularRule(single, plural, preserveCase) will do the trick for me.

davidcalhoun commented 6 years ago

Just ran into the same issue - also with the string id.

Example:

pluralize('Foo ID', 2);
// -> 'Foo IDS'

In this case I want to control the output so it can instead return 'Foo IDs'.

Thanks in advance!

baerrach commented 6 years ago

I've hacked around it.

const plural = word => {
  const result = pluralize.plural(word);
  if (word === word.toUpperCase()) {
    // Pluralize https://github.com/blakeembrey/pluralize/issues/49 doesn't
    // handle abbreviations or initialisms
    // Hack around it as there is no way to change the strategy in pluralize::restoreCase()
    const suffix = result.substr(word.length);

    return word + suffix.toLowerCase();
  }

  return result;
};