- Notifications
You must be signed in to change notification settings - Fork0
Pluralize and singularize any word.
License
encryptorcode/pluralize
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Pluralize and singularize any word.
<dependency> <groupId>io.github.encryptorcode</groupId> <artifactId>pluralize</artifactId> <version>${pluralize.version}</version></dependency>
This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.
word: stringThe word to pluralizecount: numberHow many of the word existinclusive: booleanWhether to prefix with the number (e.g. 3 ducks)
Examples:
importio.github.encryptorcode.pluralize.Pluralize;importstaticio.github.encryptorcode.pluralize.Pluralize.*;publicclassExample{publicstaticvoidmain(String[]args){pluralize("test");//=> "tests"pluralize("test",0);//=> "tests"pluralize("test",1);//=> "test"pluralize("test",5);//=> "tests"pluralize("test",1,true);//=> "1 test"pluralize("test",5,true);//=> "5 tests"pluralize("蘋果",2,true);//=> "2 蘋果"// Example of new plural rule:Pluralize.plural("regex");//=> "regexes"Pluralize.addPluralRule(p("gex$"),"gexii");Pluralize.plural("regex");//=> "regexii"// Example of new singular rule:Pluralize.singular("singles");//=> "single"Pluralize.addSingularRule(p("singles"),"singular");Pluralize.singular("singles");//=> "singular"// Example of new irregular rule, e.g. "I" -> "we":Pluralize.plural("irregular");//=> "irregulars"Pluralize.addIrregularRule("irregular","regular");Pluralize.plural("irregular");//=> "regular"// Example of uncountable rule (rules without singular/plural in context):Pluralize.plural("paper");//=> "papers"Pluralize.addUncountableRule("paper");Pluralize.plural("paper");//=> "paper"// Example of asking whether a word looks singular or plural:Pluralize.isPlural("test");//=> falsePluralize.isSingular("test");//=> true }}
The actual javascript version of this library is maintained atblakeembrey/pluralize.I've only helped to translate the code to Java. Also, I assure to have the least deviations from the actual code written and maintained by@blakeembrey
MIT
About
Pluralize and singularize any word.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.