1
0
mirror of https://github.com/jinzhu/inflection.git synced 2020-06-03 17:06:38 +00:00
Go to file
2020-02-16 18:24:04 +08:00
go.mod Add support for Go modules 2019-02-27 15:41:19 +11:00
inflections_test.go Add safety measure for test execution 2016-08-17 04:34:15 +10:00
inflections.go Add evidence to uncountable 2019-04-28 10:37:43 -07:00
LICENSE Add LICENSE 2015-10-09 16:41:29 +08:00
README.md Add wercker 2018-03-08 11:36:59 +08:00
wercker.yml Add wercker 2018-03-08 11:36:59 +08:00

Inflection

Inflection pluralizes and singularizes English nouns

wercker status

Basic Usage

inflection.Plural("person") => "people"
inflection.Plural("Person") => "People"
inflection.Plural("PERSON") => "PEOPLE"
inflection.Plural("bus")    => "buses"
inflection.Plural("BUS")    => "BUSES"
inflection.Plural("Bus")    => "Buses"

inflection.Singular("people") => "person"
inflection.Singular("People") => "Person"
inflection.Singular("PEOPLE") => "PERSON"
inflection.Singular("buses")  => "bus"
inflection.Singular("BUSES")  => "BUS"
inflection.Singular("Buses")  => "Bus"

inflection.Plural("FancyPerson") => "FancyPeople"
inflection.Singular("FancyPeople") => "FancyPerson"

Register Rules

Standard rules are from Rails's ActiveSupport (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb)

If you want to register more rules, follow:

inflection.AddUncountable("fish")
inflection.AddIrregular("person", "people")
inflection.AddPlural("(bu)s$", "${1}ses") # "bus" => "buses" / "BUS" => "BUSES" / "Bus" => "Buses"
inflection.AddSingular("(bus)(es)?$", "${1}") # "buses" => "bus" / "Buses" => "Bus" / "BUSES" => "BUS"

Contributing

You can help to make the project better, check out http://gorm.io/contribute.html for things you can do.

Author

jinzhu

License

Released under the MIT License.