Categorygithub.com/jinzhu/inflection
modulepackage
1.0.0
Repository: https://github.com/jinzhu/inflection.git
Documentation: pkg.go.dev

# README

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.

# Functions

AddIrregular adds an irregular inflection.
AddPlural adds a plural inflection.
AddSingular adds a singular inflection.
AddUncountable adds an uncountable inflection.
GetIrregular retrieves the irregular inflection values.
GetPlural retrieves the plural inflection values.
GetSingular retrieves the singular inflection values.
GetUncountable retrieves the uncountable inflection values.
Plural converts a word to its plural form.
SetIrregular sets the irregular inflections slice.
SetPlural sets the plural inflections slice.
SetSingular sets the singular inflections slice.
SetUncountable sets the uncountable inflections slice.
Singular converts a word to its singular form.

# Structs

Irregular is a hard replace inflection, containing both singular and plural forms.
Regular is a regexp find replace inflection.

# Type aliases

IrregularSlice is a slice of Irregular inflections.
RegularSlice is a slice of Regular inflections.