lazysupport

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

README

lazysupport

Variables

ShouldCache set if the inflector should (or not) cache the inflections

var ShouldCache = false

Functions

func Camelize

func Camelize(term string) string

Camelize converts strings to UpperCamelCase.

fmt.Println(Camelize("my_account"))
fmt.Println(Camelize("user-profile"))
fmt.Println(Camelize("ssl_error"))
fmt.Println(Camelize("http_connection_timeout"))
fmt.Println(Camelize("restful_controller"))
fmt.Println(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

func Dasherize(term string) string

Dasherize converts strings to dashed, lowercase form.

fmt.Println(Dasherize("MyAccount"))
fmt.Println(Dasherize("user_profile"))

Output:

my-account
user-profile
func ForeignKey

func ForeignKey(term string) string

ForeignKey creates a foreign key name from an ORM model name.

fmt.Println(ForeignKey("Message"))
fmt.Println(ForeignKey("AdminPost"))

Output:

message_id
admin_post_id
func Ordinal

func Ordinal(number int64) string

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.

fmt.Println(Ordinal(1))
fmt.Println(Ordinal(2))
fmt.Println(Ordinal(14))
fmt.Println(Ordinal(1002))
fmt.Println(Ordinal(1003))
fmt.Println(Ordinal(-11))
fmt.Println(Ordinal(-1021))

Output:

st
nd
th
nd
rd
th
st
func Ordinalize

func Ordinalize(number int64) string

Ordinalize turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.

fmt.Println(Ordinalize(1))
fmt.Println(Ordinalize(2))
fmt.Println(Ordinalize(14))
fmt.Println(Ordinalize(1002))
fmt.Println(Ordinalize(1003))
fmt.Println(Ordinalize(-11))
fmt.Println(Ordinalize(-1021))

Output:

1st
2nd
14th
1002nd
1003rd
-11th
-1021st
func Pluralize

func Pluralize(singular string) string

Pluralize returns the plural form of the word in the string.

fmt.Println(Pluralize("post"))
fmt.Println(Pluralize("octopus"))
fmt.Println(Pluralize("sheep"))
fmt.Println(Pluralize("words"))
fmt.Println(Pluralize("CamelOctopus"))

Output:

posts
octopi
sheep
words
CamelOctopi
func Singularize

func Singularize(plural string) string

Singularize returns the singular form of a word in a string.

fmt.Println(Singularize("posts"))
fmt.Println(Singularize("octopi"))
fmt.Println(Singularize("sheep"))
fmt.Println(Singularize("word"))
fmt.Println(Singularize("CamelOctopi"))

Output:

post
octopus
sheep
word
CamelOctopus
func Tableize

func Tableize(term string) string

Tableize creates the name of a table for an ORM model.

fmt.Println(Tableize("RawScaledScorer"))
fmt.Println(Tableize("ham_and_egg"))
fmt.Println(Tableize("fancyCategory"))

Output:

raw_scaled_scorers
ham_and_eggs
fancy_categories
func ToSnakeCase

func ToSnakeCase(str string) string

func Underscorize

func Underscorize(term string) string

Underscorize converts strings to underscored, lowercase form.

fmt.Println(Underscorize("MyAccount"))
fmt.Println(Underscorize("user-profile"))
fmt.Println(Underscorize("SSLError"))
fmt.Println(Underscorize("HTTPConnectionTimeout"))
fmt.Println(Underscorize("RESTfulController"))
fmt.Println(Underscorize("MultipleHTTPCalls"))

Output:

my_account
user_profile
ssl_error
http_connection_timeout
restful_controller
multiple_http_calls

Types

type Table

type Table struct { ... }

table := Table{
    Header: []string{"Title", "Age"},
    Values: [][]string{
        {"The film", "1"},
        {"The super super file"},
        {"", ""},
        {"Other Filem", "123123"},
    },
}

fmt.Println(table.String())

Output:

Title                Age
The film             1
The super super file

Other Filem          123123
func (*Table) String

func (t *Table) String() string


Readme created from Go doc with goreadme

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ShouldCache = false

ShouldCache set if the inflector should (or not) cache the inflections

Functions

func Camelize

func Camelize(term string) string

Camelize converts strings to UpperCamelCase.

Example
fmt.Println(Camelize("my_account"))
fmt.Println(Camelize("user-profile"))
fmt.Println(Camelize("ssl_error"))
fmt.Println(Camelize("http_connection_timeout"))
fmt.Println(Camelize("restful_controller"))
fmt.Println(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

func Dasherize(term string) string

Dasherize converts strings to dashed, lowercase form.

Example
fmt.Println(Dasherize("MyAccount"))
fmt.Println(Dasherize("user_profile"))
Output:

my-account
user-profile

func ForeignKey

func ForeignKey(term string) string

ForeignKey creates a foreign key name from an ORM model name.

Example
fmt.Println(ForeignKey("Message"))
fmt.Println(ForeignKey("AdminPost"))
Output:

message_id
admin_post_id

func Ordinal

func Ordinal(number int64) string

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
fmt.Println(Ordinal(1))
fmt.Println(Ordinal(2))
fmt.Println(Ordinal(14))
fmt.Println(Ordinal(1002))
fmt.Println(Ordinal(1003))
fmt.Println(Ordinal(-11))
fmt.Println(Ordinal(-1021))
Output:

st
nd
th
nd
rd
th
st

func Ordinalize

func Ordinalize(number int64) string

Ordinalize turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.

Example
fmt.Println(Ordinalize(1))
fmt.Println(Ordinalize(2))
fmt.Println(Ordinalize(14))
fmt.Println(Ordinalize(1002))
fmt.Println(Ordinalize(1003))
fmt.Println(Ordinalize(-11))
fmt.Println(Ordinalize(-1021))
Output:

1st
2nd
14th
1002nd
1003rd
-11th
-1021st

func Pluralize

func Pluralize(singular string) string

Pluralize returns the plural form of the word in the string.

Example
fmt.Println(Pluralize("post"))
fmt.Println(Pluralize("octopus"))
fmt.Println(Pluralize("sheep"))
fmt.Println(Pluralize("words"))
fmt.Println(Pluralize("CamelOctopus"))
Output:

posts
octopi
sheep
words
CamelOctopi

func Singularize

func Singularize(plural string) string

Singularize returns the singular form of a word in a string.

Example
fmt.Println(Singularize("posts"))
fmt.Println(Singularize("octopi"))
fmt.Println(Singularize("sheep"))
fmt.Println(Singularize("word"))
fmt.Println(Singularize("CamelOctopi"))
Output:

post
octopus
sheep
word
CamelOctopus

func Tableize

func Tableize(term string) string

Tableize creates the name of a table for an ORM model.

Example
fmt.Println(Tableize("RawScaledScorer"))
fmt.Println(Tableize("ham_and_egg"))
fmt.Println(Tableize("fancyCategory"))
Output:

raw_scaled_scorers
ham_and_eggs
fancy_categories

func ToSnakeCase

func ToSnakeCase(str string) string

func Underscorize

func Underscorize(term string) string

Underscorize converts strings to underscored, lowercase form.

Example
fmt.Println(Underscorize("MyAccount"))
fmt.Println(Underscorize("user-profile"))
fmt.Println(Underscorize("SSLError"))
fmt.Println(Underscorize("HTTPConnectionTimeout"))
fmt.Println(Underscorize("RESTfulController"))
fmt.Println(Underscorize("MultipleHTTPCalls"))
Output:

my_account
user_profile
ssl_error
http_connection_timeout
restful_controller
multiple_http_calls

Types

type Table

type Table struct {
	Header []string
	Values [][]string
}
Example
table := Table{
	Header: []string{"Title", "Age"},
	Values: [][]string{
		{"The film", "1"},
		{"The super super file"},
		{"", ""},
		{"Other Filem", "123123"},
	},
}

fmt.Println(table.String())
Output:

Title                Age
The film             1
The super super file

Other Filem          123123

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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