JavaScript pluralize an english string

前端 未结 11 1022
南旧
南旧 2020-12-23 16:24

In PHP, I use Kuwamoto\'s class to pluralize nouns in my strings. I didn\'t find something as good as this script in javascript except for some plugins. So, it would be grea

11条回答
  •  借酒劲吻你
    2020-12-23 17:04

    Use Pluralize

    There's a great little library called Pluralize that's packaged in npm and bower.

    This is what it looks like to use:

    import Pluralize from 'pluralize';
    
    Pluralize( 'Towel', 42 );       // "Towels"
    
    Pluralize( 'Towel', 42, true ); // "42 Towels"
    

    And you can get it here:

    https://github.com/blakeembrey/pluralize

提交回复
热议问题