Documentation ¶
Overview ¶
Package inflection pluralizes and singularizes English nouns.
inflection.Plural("person") => "people" inflection.Plural("Person") => "People" inflection.Plural("PERSON") => "PEOPLE" inflection.Singular("people") => "person" inflection.Singular("People") => "Person" inflection.Singular("PEOPLE") => "PERSON" inflection.Plural("FancyPerson") => "FancydPeople" inflection.Singular("FancyPeople") => "FancydPerson"
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"
Index ¶
- func AddIrregular(singular, plural string)
- func AddPlural(find, replace string)
- func AddSingular(find, replace string)
- func AddUncountable(values ...string)
- func GetUncountable() []string
- func Plural(str string) string
- func SetIrregular(inflections IrregularSlice)
- func SetPlural(inflections RegularSlice)
- func SetSingular(inflections RegularSlice)
- func SetUncountable(inflections []string)
- func Singular(str string) string
- type Irregular
- type IrregularSlice
- type Regular
- type RegularSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddIrregular ¶
func AddIrregular(singular, plural string)
AddIrregular adds an irregular inflection
func AddUncountable ¶
func AddUncountable(values ...string)
AddUncountable adds an uncountable inflection
func GetUncountable ¶
func GetUncountable() []string
GetUncountable retrieves the uncountable inflection values
func SetIrregular ¶
func SetIrregular(inflections IrregularSlice)
SetIrregular sets the irregular inflections slice
func SetPlural ¶
func SetPlural(inflections RegularSlice)
SetPlural sets the plural inflections slice
func SetSingular ¶
func SetSingular(inflections RegularSlice)
SetSingular sets the singular inflections slice
func SetUncountable ¶
func SetUncountable(inflections []string)
SetUncountable sets the uncountable inflections slice
Types ¶
type Irregular ¶
type Irregular struct {
// contains filtered or unexported fields
}
Irregular is a hard replace inflection, containing both singular and plural forms
type IrregularSlice ¶
type IrregularSlice []Irregular
IrregularSlice is a slice of Irregular inflections
func GetIrregular ¶
func GetIrregular() IrregularSlice
GetIrregular retrieves the irregular inflection values
type Regular ¶
type Regular struct {
// contains filtered or unexported fields
}
Regular is a regexp find replace inflection
type RegularSlice ¶
type RegularSlice []Regular
RegularSlice is a slice of Regular inflections
func GetSingular ¶
func GetSingular() RegularSlice
GetSingular retrieves the singular inflection values