Browse Source

refactored doc to please golint

tags/v0.1.0
Ma_124 5 years ago
parent
commit
dfc5dc8c6d
3 changed files with 20 additions and 9 deletions
  1. +2
    -2
      camel.go
  2. +12
    -0
      doc.go
  3. +6
    -7
      snake.go

+ 2
- 2
camel.go View File

@@ -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


+ 12
- 0
doc.go 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

+ 6
- 7
snake.go View File

@@ -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, " ")


Loading…
Cancel
Save