Documentation ¶
Index ¶
- Variables
- func Camelize(term string) string
- func ClearCache()
- func Dasherize(term string) string
- func ForeignKey(term string) string
- func Ordinal(number int64) string
- func Ordinalize(number int64) string
- func Pluralize(singular string) string
- func Singularize(plural string) string
- func Tableize(term string) string
- func Underscorize(term string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ShouldCache = false
ShouldCache set if the inflector should (or not) cache the inflections
Functions ¶
func Camelize ¶
Camelize converts strings to UpperCamelCase.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Camelize("my_account")) fmt.Println(inflector.Camelize("user-profile")) fmt.Println(inflector.Camelize("ssl_error")) fmt.Println(inflector.Camelize("http_connection_timeout")) fmt.Println(inflector.Camelize("restful_controller")) fmt.Println(inflector.Camelize("multiple_http_calls")) }
Output: MyAccount UserProfile SSLError HTTPConnectionTimeout RESTfulController MultipleHTTPCalls
func ClearCache ¶
func ClearCache()
ClearCache clear the inflection cache. Both for singulars and plurals.
func Dasherize ¶
Dasherize converts strings to dashed, lowercase form.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Dasherize("MyAccount")) fmt.Println(inflector.Dasherize("user_profile")) }
Output: my-account user-profile
func ForeignKey ¶
ForeignKey creates a foreign key name from an ORM model name.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.ForeignKey("Message")) fmt.Println(inflector.ForeignKey("AdminPost")) }
Output: message_id admin_post_id
func Ordinal ¶
Ordinal returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Ordinal(1)) fmt.Println(inflector.Ordinal(2)) fmt.Println(inflector.Ordinal(14)) fmt.Println(inflector.Ordinal(1002)) fmt.Println(inflector.Ordinal(1003)) fmt.Println(inflector.Ordinal(-11)) fmt.Println(inflector.Ordinal(-1021)) }
Output: st nd th nd rd th st
func Ordinalize ¶
Ordinalize turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Ordinalize(1)) fmt.Println(inflector.Ordinalize(2)) fmt.Println(inflector.Ordinalize(14)) fmt.Println(inflector.Ordinalize(1002)) fmt.Println(inflector.Ordinalize(1003)) fmt.Println(inflector.Ordinalize(-11)) fmt.Println(inflector.Ordinalize(-1021)) }
Output: 1st 2nd 14th 1002nd 1003rd -11th -1021st
func Pluralize ¶
Pluralize returns the plural form of the word in the string.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Pluralize("post")) fmt.Println(inflector.Pluralize("octopus")) fmt.Println(inflector.Pluralize("sheep")) fmt.Println(inflector.Pluralize("words")) fmt.Println(inflector.Pluralize("CamelOctopus")) }
Output: posts octopi sheep words CamelOctopi
func Singularize ¶
Singularize returns the singular form of a word in a string.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Singularize("posts")) fmt.Println(inflector.Singularize("octopi")) fmt.Println(inflector.Singularize("sheep")) fmt.Println(inflector.Singularize("word")) fmt.Println(inflector.Singularize("CamelOctopi")) }
Output: post octopus sheep word CamelOctopus
func Tableize ¶
Tableize creates the name of a table for an ORM model.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Tableize("RawScaledScorer")) fmt.Println(inflector.Tableize("ham_and_egg")) fmt.Println(inflector.Tableize("fancyCategory")) }
Output: raw_scaled_scorers ham_and_eggs fancy_categories
func Underscorize ¶
Underscorize converts strings to underscored, lowercase form.
Example ¶
package main import ( "fmt" "github.com/tangzero/inflector" ) func main() { fmt.Println(inflector.Underscorize("MyAccount")) fmt.Println(inflector.Underscorize("user-profile")) fmt.Println(inflector.Underscorize("SSLError")) fmt.Println(inflector.Underscorize("HTTPConnectionTimeout")) fmt.Println(inflector.Underscorize("RESTfulController")) fmt.Println(inflector.Underscorize("MultipleHTTPCalls")) }
Output: my_account user_profile ssl_error http_connection_timeout restful_controller multiple_http_calls
Types ¶
This section is empty.