From 57e49c95205cabef5cba808466989e90e73f8e8e Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 14 Dec 2022 21:42:43 +0800 Subject: [PATCH] doc: update document for funcations CamelCase/KebabCase/UpperKebabCase/SnakeCase/UpperSnakeCase --- docs/strutil.md | 114 +++++++++++++++++++++++++++++++++++++++--- docs/strutil_zh-CN.md | 88 +++++++++++++++++++++++++++++--- 2 files changed, 187 insertions(+), 15 deletions(-) diff --git a/docs/strutil.md b/docs/strutil.md index 5578f81..d7aa98a 100644 --- a/docs/strutil.md +++ b/docs/strutil.md @@ -28,12 +28,14 @@ import ( - [Capitalize](#Capitalize) - [IsString](#IsString) - [KebabCase](#KebabCase) +- [UpperKebabCase](#UpperKebabCase) - [LowerFirst](#LowerFirst) - [UpperFirst](#UpperFirst) - [PadEnd](#PadEnd) - [PadStart](#PadStart) - [Reverse](#Reverse) - [SnakeCase](#SnakeCase) +- [UpperSnakeCase](#UpperSnakeCase) - [SplitEx](#SplitEx) - [Wrap](#Wrap) - [Unwrap](#Unwrap) @@ -165,10 +167,8 @@ func main() { ``` - - ### CamelCase -

Covert string to camelCase string.

+

Coverts string to camelCase string, non letters and numbers will be ignored.

Signature: @@ -195,6 +195,73 @@ func main() { s4 := strutil.CamelCase("foo bar") fmt.Println(s4) //fooBar + + s4 := strutil.CamelCase("Foo-#1😄$_%^&*(1bar") + fmt.Println(s4) //foo11Bar +``` + + +### KebabCase +

KebabCase covert string to kebab-case, non letters and numbers will be ignored.

+ +Signature: + +```go +func KebabCase(s string) string +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/strutil" +) + +func main() { + s1 := strutil.KebabCase("Foo Bar-") + fmt.Println(s1) //foo-bar + + s2 := strutil.KebabCase("foo_Bar") + fmt.Println(s2) //foo-bar + + s3 := strutil.KebabCase("fooBar") + fmt.Println(s3) //foo-bar + + s4 := strutil.KebabCase("__FOO_BAR__") + fmt.Println(s4) //foo-bar +} +``` + + + +### UpperKebabCase +

UpperKebabCase covert string to upper KEBAB-CASE, non letters and numbers will be ignored.

+ +Signature: + +```go +func KebabCase(s string) string +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/strutil" +) + +func main() { + s1 := strutil.UpperKebabCase("Foo Bar-") + fmt.Println(s1) //FOO-BAR + + s2 := strutil.UpperKebabCase("foo_Bar") + fmt.Println(s2) //FOO-BAR + + s3 := strutil.UpperKebabCase("fooBar") + fmt.Println(s3) //FOO-BAR + + s4 := strutil.UpperKebabCase("__FOO_BAR__") + fmt.Println(s4) //FOO-BAR } ``` @@ -457,7 +524,7 @@ func main() { ### SnakeCase -

Covert string to snake_case.

+

Coverts string to snake_case, non letters and numbers will be ignored.

Signature: @@ -483,14 +550,47 @@ func main() { fmt.Println(s3) //foo_bar s4 := strutil.SnakeCase("__FOO_BAR__") - fmt.Println(s4) //f_o_o_b_a_r + fmt.Println(s4) //foo_bar - s5 := strutil.SnakeCase("aBbc-s$@a&%_B.B^C") - fmt.Println(s5) //a_bbc_s_a_b_b_c + s5 := strutil.SnakeCase("Foo-#1😄$_%^&*(1bar") + fmt.Println(s5) //foo_1_1_bar } ``` +### UpperSnakeCase +

Coverts string to upper KEBAB-CASE, non letters and numbers will be ignored.

+ +Signature: + +```go +func SnakeCase(s string) string +``` +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/strutil" +) + +func main() { + s1 := strutil.UpperSnakeCase("Foo Bar-") + fmt.Println(s1) //FOO_BAR + + s2 := strutil.UpperSnakeCase("foo_Bar") + fmt.Println(s2) //FOO_BAR + + s3 := strutil.UpperSnakeCase("fooBar") + fmt.Println(s3) //FOO_BAR + + s4 := strutil.UpperSnakeCase("__FOO_BAR__") + fmt.Println(s4) //FOO_BAR + + s5 := strutil.UpperSnakeCase("Foo-#1😄$_%^&*(1bar") + fmt.Println(s5) //FOO_1_1_BAR +} +``` ### SplitEx diff --git a/docs/strutil_zh-CN.md b/docs/strutil_zh-CN.md index 75b9f02..8780dbd 100644 --- a/docs/strutil_zh-CN.md +++ b/docs/strutil_zh-CN.md @@ -28,12 +28,14 @@ import ( - [Capitalize](#Capitalize) - [IsString](#IsString) - [KebabCase](#KebabCase) +- [UpperKebabCase](#UpperKebabCase) - [LowerFirst](#LowerFirst) - [UpperFirst](#UpperFirst) - [PadEnd](#PadEnd) - [PadStart](#PadStart) - [Reverse](#Reverse) - [SnakeCase](#SnakeCase) +- [UpperSnakeCase](#UpperSnakeCase) - [SplitEx](#SplitEx) - [Wrap](#Wrap) - [Unwrap](#Unwrap) @@ -169,7 +171,7 @@ func main() { ### CamelCase -

将字符串转换为驼峰式字符串

+

将字符串转换为驼峰式字符串, 非字母和数字会被忽略

函数签名: @@ -196,7 +198,9 @@ func main() { s4 := strutil.CamelCase("foo bar") fmt.Println(s4) //fooBar -} + + s4 := strutil.CamelCase("Foo-#1😄$_%^&*(1bar") + fmt.Println(s4) //foo11Bar ``` @@ -261,7 +265,7 @@ func main() { ### KebabCase -

将字符串转换为kebab-case

+

将字符串转换为kebab-case, 非字母和数字会被忽略

函数签名: @@ -287,7 +291,40 @@ func main() { fmt.Println(s3) //foo-bar s4 := strutil.KebabCase("__FOO_BAR__") - fmt.Println(s4) //f-o-o-b-a-r + fmt.Println(s4) //foo-bar +} +``` + + + +### UpperKebabCase +

将字符串转换为大写KEBAB-CASE, 非字母和数字会被忽略

+ +函数签名: + +```go +func KebabCase(s string) string +``` +例子: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/strutil" +) + +func main() { + s1 := strutil.UpperKebabCase("Foo Bar-") + fmt.Println(s1) //FOO-BAR + + s2 := strutil.UpperKebabCase("foo_Bar") + fmt.Println(s2) //FOO-BAR + + s3 := strutil.UpperKebabCase("fooBar") + fmt.Println(s3) //FOO-BAR + + s4 := strutil.UpperKebabCase("__FOO_BAR__") + fmt.Println(s4) //FOO-BAR } ``` @@ -458,7 +495,7 @@ func main() { ### SnakeCase -

将字符串转换为snake_case形式

+

将字符串转换为snake_case形式, 非字母和数字会被忽略

函数签名: @@ -484,10 +521,45 @@ func main() { fmt.Println(s3) //foo_bar s4 := strutil.SnakeCase("__FOO_BAR__") - fmt.Println(s4) //f_o_o_b_a_r + fmt.Println(s4) //foo_bar - s5 := strutil.SnakeCase("aBbc-s$@a&%_B.B^C") - fmt.Println(s5) //a_bbc_s_a_b_b_c + s5 := strutil.SnakeCase("Foo-#1😄$_%^&*(1bar") + fmt.Println(s5) //foo_1_1_bar +} +``` + + +### UpperSnakeCase +

将字符串转换为大写SNAKE_CASE形式, 非字母和数字会被忽略

+ +函数签名: + +```go +func SnakeCase(s string) string +``` +例子: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/strutil" +) + +func main() { + s1 := strutil.UpperSnakeCase("Foo Bar-") + fmt.Println(s1) //FOO_BAR + + s2 := strutil.UpperSnakeCase("foo_Bar") + fmt.Println(s2) //FOO_BAR + + s3 := strutil.UpperSnakeCase("fooBar") + fmt.Println(s3) //FOO_BAR + + s4 := strutil.UpperSnakeCase("__FOO_BAR__") + fmt.Println(s4) //FOO_BAR + + s5 := strutil.UpperSnakeCase("Foo-#1😄$_%^&*(1bar") + fmt.Println(s5) //FOO_1_1_BAR } ```