refactored doc to please golint

This commit is contained in:
Ma_124 2019-04-19 09:12:49 +02:00
parent d73be125f8
commit dfc5dc8c6d
3 changed files with 20 additions and 9 deletions

View File

@ -58,12 +58,12 @@ func toCamelInitCase(s string, initCase bool) string {
return n return n
} }
// Converts a string to CamelCase // ToCamel converts a string to CamelCase
func ToCamel(s string) string { func ToCamel(s string) string {
return toCamelInitCase(s, true) return toCamelInitCase(s, true)
} }
// Converts a string to lowerCamelCase // ToLowerCamel converts a string to lowerCamelCase
func ToLowerCamel(s string) string { func ToLowerCamel(s string) string {
if s == "" { if s == "" {
return s return s

12
doc.go Normal file
View File

@ -0,0 +1,12 @@
// Package strcase converts strings to various cases. See the conversion table below:
// | Function | Result |
// |---------------------------------|--------------------|
// | ToSnake(s) | any_kind_of_string |
// | ToScreamingSnake(s) | ANY_KIND_OF_STRING |
// | ToKebab(s) | any-kind-of-string |
// | ToScreamingKebab(s) | ANY-KIND-OF-STRING |
// | ToDelimited(s, '.') | any.kind.of.string |
// | ToScreamingDelimited(s, '.') | ANY.KIND.OF.STRING |
// | ToCamel(s) | AnyKindOfString |
// | ToLowerCamel(s) | anyKindOfString |
package strcase

View File

@ -23,39 +23,38 @@
* SOFTWARE. * SOFTWARE.
*/ */
// Package strcase converts strings to snake_case or CamelCase
package strcase package strcase
import ( import (
"strings" "strings"
) )
// Converts a string to snake_case // ToSnake converts a string to snake_case
func ToSnake(s string) string { func ToSnake(s string) string {
return ToDelimited(s, '_') return ToDelimited(s, '_')
} }
// Converts a string to SCREAMING_SNAKE_CASE // ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE
func ToScreamingSnake(s string) string { func ToScreamingSnake(s string) string {
return ToScreamingDelimited(s, '_', true) return ToScreamingDelimited(s, '_', true)
} }
// Converts a string to kebab-case // ToKebab converts a string to kebab-case
func ToKebab(s string) string { func ToKebab(s string) string {
return ToDelimited(s, '-') return ToDelimited(s, '-')
} }
// Converts a string to SCREAMING-KEBAB-CASE // ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE
func ToScreamingKebab(s string) string { func ToScreamingKebab(s string) string {
return ToScreamingDelimited(s, '-', true) return ToScreamingDelimited(s, '-', true)
} }
// Converts a string to delimited.snake.case (in this case `del = '.'`) // ToDelimited converts a string to delimited.snake.case (in this case `del = '.'`)
func ToDelimited(s string, del uint8) string { func ToDelimited(s string, del uint8) string {
return ToScreamingDelimited(s, del, false) return ToScreamingDelimited(s, del, false)
} }
// Converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`) // ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`)
func ToScreamingDelimited(s string, del uint8, screaming bool) string { func ToScreamingDelimited(s string, del uint8, screaming bool) string {
s = addWordBoundariesToNumbers(s) s = addWordBoundariesToNumbers(s)
s = strings.Trim(s, " ") s = strings.Trim(s, " ")