From dfc5dc8c6d1a0c391bb5a4ded09769dfaad58047 Mon Sep 17 00:00:00 2001 From: Ma_124 Date: Fri, 19 Apr 2019 09:12:49 +0200 Subject: [PATCH] refactored doc to please golint --- camel.go | 4 ++-- doc.go | 12 ++++++++++++ snake.go | 13 ++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 doc.go diff --git a/camel.go b/camel.go index 7c2e2b7..9f3381a 100644 --- a/camel.go +++ b/camel.go @@ -58,12 +58,12 @@ func toCamelInitCase(s string, initCase bool) string { return n } -// Converts a string to CamelCase +// ToCamel converts a string to CamelCase func ToCamel(s string) string { return toCamelInitCase(s, true) } -// Converts a string to lowerCamelCase +// ToLowerCamel converts a string to lowerCamelCase func ToLowerCamel(s string) string { if s == "" { return s diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..5e1825b --- /dev/null +++ b/doc.go @@ -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 diff --git a/snake.go b/snake.go index 1d2f520..b553b97 100644 --- a/snake.go +++ b/snake.go @@ -23,39 +23,38 @@ * SOFTWARE. */ -// Package strcase converts strings to snake_case or CamelCase package strcase import ( "strings" ) -// Converts a string to snake_case +// ToSnake converts a string to snake_case func ToSnake(s string) string { return ToDelimited(s, '_') } -// Converts a string to SCREAMING_SNAKE_CASE +// ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE func ToScreamingSnake(s string) string { return ToScreamingDelimited(s, '_', true) } -// Converts a string to kebab-case +// ToKebab converts a string to kebab-case func ToKebab(s string) string { return ToDelimited(s, '-') } -// Converts a string to SCREAMING-KEBAB-CASE +// ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE func ToScreamingKebab(s string) string { 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 { 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 { s = addWordBoundariesToNumbers(s) s = strings.Trim(s, " ")