pluralize icon indicating copy to clipboard operation
pluralize copied to clipboard

Abbreviated words

Open daut opened this issue 8 years ago • 4 comments
trafficstars

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!

daut avatar Feb 06 '17 18:02 daut

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?

blakeembrey avatar Feb 07 '17 03:02 blakeembrey

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.

daut avatar Feb 07 '17 08:02 daut

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!

davidcalhoun avatar Jan 09 '18 22:01 davidcalhoun

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

baerrach avatar Sep 17 '18 02:09 baerrach