inflection

package module
Version: v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 2 Imported by: 497

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.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIrregular

func AddIrregular(singular, plural string)

AddIrregular adds an irregular inflection

func AddPlural

func AddPlural(find, replace string)

AddPlural adds a plural inflection

func AddSingular

func AddSingular(find, replace string)

AddSingular adds a singular inflection

func AddUncountable

func AddUncountable(values ...string)

AddUncountable adds an uncountable inflection

func GetUncountable

func GetUncountable() []string

GetUncountable retrieves the uncountable inflection values

func Plural

func Plural(str string) string

Plural converts a word to its plural form

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

func Singular

func Singular(str string) string

Singular converts a word to its singular form

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 GetPlural

func GetPlural() RegularSlice

GetPlural retrieves the plural inflection values

func GetSingular

func GetSingular() RegularSlice

GetSingular retrieves the singular inflection values

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL