inflect – github.com/markbates/inflect Index | Files

package inflect

import "github.com/markbates/inflect"

Index

Constants

const Version = "v1.0.4"

Variables

var Helpers = map[string]interface{}{
	"asciffy":             Asciify,
	"camelize":            Camelize,
	"camelize_down_first": CamelizeDownFirst,
	"capitalize":          Capitalize,
	"dasherize":           Dasherize,
	"humanize":            Humanize,
	"ordinalize":          Ordinalize,
	"parameterize":        Parameterize,
	"pluralize":           Pluralize,
	"pluralize_with_size": PluralizeWithSize,
	"singularize":         Singularize,
	"tableize":            Tableize,
	"typeify":             Typeify,
	"underscore":          Underscore,
}

Helpers is a map of the helper names with its corresponding inflect function

Functions

func AddAcronym

func AddAcronym(word string)

func AddHuman

func AddHuman(suffix, replacement string)

AddHuman adds human

func AddIrregular

func AddIrregular(singular, plural string)

func AddPlural

func AddPlural(suffix, replacement string)

AddPlural adds plural to the ruleset

func AddSingular

func AddSingular(suffix, replacement string)

AddSingular adds singular to the ruleset

func AddUncountable

func AddUncountable(word string)

func Asciify

func Asciify(word string) string

func Camelize

func Camelize(word string) string

func CamelizeDownFirst

func CamelizeDownFirst(word string) string

func Capitalize

func Capitalize(word string) string

func Dasherize

func Dasherize(word string) string

func ForeignKey

func ForeignKey(word string) string

func ForeignKeyCondensed

func ForeignKeyCondensed(word string) string

func ForeignKeyToAttribute

func ForeignKeyToAttribute(word string) string

func Humanize

func Humanize(word string) string

func LoadReader

func LoadReader(r io.Reader) error

LoadReader loads rules from io.Reader param

func Ordinalize

func Ordinalize(word string) string

func Parameterize

func Parameterize(word string) string

func ParameterizeJoin

func ParameterizeJoin(word, sep string) string

func Pluralize

func Pluralize(word string) string

func PluralizeWithSize

func PluralizeWithSize(word string, size int) string

func Singularize

func Singularize(word string) string

func Tableize

func Tableize(word string) string

func Titleize

func Titleize(word string) string

func Typeify

func Typeify(word string) string

func Uncountables

func Uncountables() map[string]bool

Uncountables returns a list of uncountables rules

func Underscore

func Underscore(word string) string

Types

type Name

type Name string

Name is a string that represents the "name" of a thing, like an app, model, etc...

func (Name) Camel

func (n Name) Camel() string

Camel version of a name

func (Name) CamelSingular

func (n Name) CamelSingular() string

CamelSingular version of a name

func (Name) Char

func (n Name) Char() string

Char returns first character in lower case, this is useful for methods inside a struct.

func (Name) File

func (n Name) File() string

File version of a name

func (Name) Lower

func (n Name) Lower() string

Lower case version of a string

func (Name) Model

func (n Name) Model() string

Model version of a name. ie. "user" => "User"

func (Name) ModelPlural

func (n Name) ModelPlural() string

ModelPlural version of a name. ie. "user" => "Users"

func (Name) Package

func (n Name) Package() string

Package returns go package

func (Name) ParamID

func (n Name) ParamID() string

ParamID returns foo_bar_id

func (Name) Plural

func (n Name) Plural() string

Plural version of a name

func (Name) PluralCamel

func (n Name) PluralCamel() string

PluralCamel version of a name

func (Name) PluralUnder

func (n Name) PluralUnder() string

PluralUnder version of a name

func (Name) Resource

func (n Name) Resource() string

Resource version of a name

func (Name) Singular

func (n Name) Singular() string

Singular version of a name

func (Name) String

func (n Name) String() string

func (Name) Table

func (n Name) Table() string

Table version of a name

func (Name) Title

func (n Name) Title() string

Title version of a name. ie. "foo_bar" => "Foo Bar"

func (Name) URL

func (n Name) URL() string

URL version of a name

func (Name) UnderSingular

func (n Name) UnderSingular() string

UnderSingular version of a name

func (Name) Underscore

func (n Name) Underscore() string

Underscore version of a name. ie. "FooBar" => "foo_bar"

func (Name) VarCasePlural

func (n Name) VarCasePlural() string

VarCasePlural version of a name. ie. "FooBar" => "fooBar"

func (Name) VarCaseSingular

func (n Name) VarCaseSingular() string

VarCaseSingular version of a name. ie. "FooBar" => "fooBar"

type Rule

type Rule struct {
	// contains filtered or unexported fields
}

Rule used by rulesets

type Ruleset

type Ruleset struct {
	// contains filtered or unexported fields
}

Ruleset a Ruleset is the config of pluralization rules you can extend the rules with the Add* methods

func NewDefaultRuleset

func NewDefaultRuleset() *Ruleset

NewDefaultRuleset creates a new ruleset and load it with the default set of common English pluralization rules

func NewRuleset

func NewRuleset() *Ruleset

NewRuleset creates a blank ruleset. Unless you are going to build your own rules from scratch you probably won't need this and can just use the defaultRuleset via the global inflect.* methods

func (*Ruleset) AddAcronym

func (rs *Ruleset) AddAcronym(word string)

AddAcronym if you use acronym you may need to add them to the ruleset to prevent Underscored words of things like "HTML" coming out as "h_t_m_l"

func (*Ruleset) AddHuman

func (rs *Ruleset) AddHuman(suffix, replacement string)

AddHuman Human rules are applied by humanize to show more friendly versions of words

func (*Ruleset) AddIrregular

func (rs *Ruleset) AddIrregular(singular, plural string)

AddIrregular Add any inconsistent pluralizing/singularizing rules to the set here.

func (*Ruleset) AddPlural

func (rs *Ruleset) AddPlural(suffix, replacement string)

AddPlural add a pluralization rule

func (*Ruleset) AddPluralExact

func (rs *Ruleset) AddPluralExact(suffix, replacement string, exact bool)

AddPluralExact add a pluralization rule with full string match

func (*Ruleset) AddSingular

func (rs *Ruleset) AddSingular(suffix, replacement string)

AddSingular add a singular rule

func (*Ruleset) AddSingularExact

func (rs *Ruleset) AddSingularExact(suffix, replacement string, exact bool)

AddSingularExact same as AddSingular but you can set `exact` to force a full string match

func (*Ruleset) AddUncountable

func (rs *Ruleset) AddUncountable(word string)

AddUncountable add a word to this ruleset that has the same singular and plural form for example: "rice"

func (*Ruleset) Asciify

func (rs *Ruleset) Asciify(word string) string

Asciify transforms Latin characters like é -> e

func (*Ruleset) Camelize

func (rs *Ruleset) Camelize(word string) string

Camelize "dino_party" -> "DinoParty"

func (*Ruleset) CamelizeDownFirst

func (rs *Ruleset) CamelizeDownFirst(word string) string

CamelizeDownFirst same as Camelcase but with first letter downcased

func (*Ruleset) Capitalize

func (rs *Ruleset) Capitalize(word string) string

Capitalize uppercase first character

func (*Ruleset) Dasherize

func (rs *Ruleset) Dasherize(word string) string

Dasherize "SomeText" -> "some-text"

func (*Ruleset) ForeignKey

func (rs *Ruleset) ForeignKey(word string) string

ForeignKey an underscored foreign key name "Person" -> "person_id"

func (*Ruleset) ForeignKeyCondensed

func (rs *Ruleset) ForeignKeyCondensed(word string) string

ForeignKeyCondensed a foreign key (with an underscore) "Person" -> "personid"

func (*Ruleset) ForeignKeyToAttribute

func (rs *Ruleset) ForeignKeyToAttribute(str string) string

ForeignKeyToAttribute returns the attribute name from the foreign key

func (*Ruleset) Humanize

func (rs *Ruleset) Humanize(word string) string

Humanize First letter of sentence capitalized Uses custom friendly replacements via AddHuman()

func (*Ruleset) LoadReader

func (rs *Ruleset) LoadReader(r io.Reader) error

LoadReader loads rules from io.Reader param

func (*Ruleset) Ordinalize

func (rs *Ruleset) Ordinalize(str string) string

Ordinalize "1031" -> "1031st"

func (*Ruleset) Parameterize

func (rs *Ruleset) Parameterize(word string) string

Parameterize param safe dasherized names like "my-param"

func (*Ruleset) ParameterizeJoin

func (rs *Ruleset) ParameterizeJoin(word, sep string) string

ParameterizeJoin param safe dasherized names with custom separator

func (*Ruleset) Pluralize

func (rs *Ruleset) Pluralize(word string) string

Pluralize returns the plural form of a singular word

func (*Ruleset) PluralizeWithSize

func (rs *Ruleset) PluralizeWithSize(word string, size int) string

PluralizeWithSize pluralize with taking number into account

func (*Ruleset) Singularize

func (rs *Ruleset) Singularize(word string) string

Singularize returns the singular form of a plural word

func (*Ruleset) Tableize

func (rs *Ruleset) Tableize(word string) string

Tableize Rails style pluralized table names: "SuperPerson" -> "super_people"

func (*Ruleset) Titleize

func (rs *Ruleset) Titleize(word string) string

Titleize Capitalize every word in sentence "hello there" -> "Hello There"

func (*Ruleset) Typeify

func (rs *Ruleset) Typeify(word string) string

Typeify "something_like_this" -> "SomethingLikeThis"

func (*Ruleset) Uncountables

func (rs *Ruleset) Uncountables() map[string]bool

Uncountables returns a map of uncountables in the ruleset

func (*Ruleset) Underscore

func (rs *Ruleset) Underscore(word string) string

Underscore lowercase underscore version "BigBen" -> "big_ben"

Source Files

helpers.go inflect.go name.go version.go

Version
v1.0.4 (latest)
Published
Oct 24, 2018
Platform
js/wasm
Imports
13 packages
Last checked
now

Tools for package owners.