From 147e4a498dc52ee78e5313354c6e3771199d2da4 Mon Sep 17 00:00:00 2001 From: shockerli Date: Sat, 30 Nov 2024 21:04:02 +0800 Subject: [PATCH] update docs --- doc/content/en/type/map.md | 17 ++++++++++++++++ doc/content/en/type/others.md | 28 +++++++++++++++++++++++++ doc/content/zh-cn/type/map.md | 17 ++++++++++++++++ doc/content/zh-cn/type/others.md | 35 +++++++++++++++++++++++++++++--- 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/doc/content/en/type/map.md b/doc/content/en/type/map.md index 75d598a..fbafe0e 100644 --- a/doc/content/en/type/map.md +++ b/doc/content/en/type/map.md @@ -9,6 +9,7 @@ weight: 70 ## StringMapE - Map + ```go // expect: map[string]interface{}{"111": "cvt", "222": 3.21} cvt.StringMapE(map[interface{}]interface{}{111: "cvt", "222": 3.21}) @@ -25,11 +26,27 @@ cvt.StringMapE(struct { ``` - JSON + ```go // expect: map[string]interface{}{"name": "cvt", "age": 3.21} cvt.StringMapE(`{"name":"cvt","age":3.21}`) ``` +## IntMapE + +- Map + +```go +// expect: map[int]interface{}{111: "cvt", 222: 3.21} +cvt.IntMapE(map[interface{}]interface{}{111: "cvt", "222": 3.21}) +``` + +- JSON + +```go +// expect: map[int]interface{}{1: "cvt", 2: 3.21} +cvt.IntMapE(`{"1":"cvt","2":3.21}`) +``` > More case see unit: `map_test.go` diff --git a/doc/content/en/type/others.md b/doc/content/en/type/others.md index f651721..e9f009a 100644 --- a/doc/content/en/type/others.md +++ b/doc/content/en/type/others.md @@ -34,6 +34,34 @@ Combine with other methods: cvt.Int(cvt.Field(map[int]interface{}{123: "112233"}, 123)) // 112233 ``` +## Len +return size of string, slice, array or map. + +```go +cvt.Len("Hello") // 5 +cvt.Len([]int{1, 2, 3}) // 3 +cvt.Len([]interface{}{1, "2", 3.0}}) // 3 +cvt.Len(map[int]interface{}{1: 1, 2: 2}) // 2 +``` + +## IsEmpty +checks value for empty state. + +```go +cvt.IsEmpty("") // true +cvt.IsEmpty("123") // false +cvt.IsEmpty(nil) // true +cvt.IsEmpty(true) // false +cvt.IsEmpty(false) // true +cvt.IsEmpty(0) // true +cvt.IsEmpty(1) // false +cvt.IsEmpty(180) // false +cvt.IsEmpty(1.23) // false +cvt.IsEmpty([]bool{}) // true +cvt.IsEmpty([]int{1, 2}) // false +cvt.IsEmpty(map[int]interface{}(nil)) // true +cvt.IsEmpty(map[string]string{"1": "1", "2": "2"}) // false +``` > More case see unit: `cvte_test.go` diff --git a/doc/content/zh-cn/type/map.md b/doc/content/zh-cn/type/map.md index ff6408b..0d7e451 100644 --- a/doc/content/zh-cn/type/map.md +++ b/doc/content/zh-cn/type/map.md @@ -9,6 +9,7 @@ weight: 70 ## StringMapE - Map + ```go // expect: map[string]interface{}{"111": "cvt", "222": 3.21} cvt.StringMapE(map[interface{}]interface{}{111: "cvt", "222": 3.21}) @@ -25,11 +26,27 @@ cvt.StringMapE(struct { ``` - JSON + ```go // expect: map[string]interface{}{"name": "cvt", "age": 3.21} cvt.StringMapE(`{"name":"cvt","age":3.21}`) ``` +## IntMapE + +- Map + +```go +// expect: map[int]interface{}{111: "cvt", 222: 3.21} +cvt.IntMapE(map[interface{}]interface{}{111: "cvt", "222": 3.21}) +``` + +- JSON + +```go +// expect: map[int]interface{}{1: "cvt", 2: 3.21} +cvt.IntMapE(`{"1":"cvt","2":3.21}`) +``` > 更多示例请看单元测试:`map_test.go` diff --git a/doc/content/zh-cn/type/others.md b/doc/content/zh-cn/type/others.md index 308256a..2b5e70c 100644 --- a/doc/content/zh-cn/type/others.md +++ b/doc/content/zh-cn/type/others.md @@ -8,10 +8,10 @@ weight: 80 ## Field -参考 `FieldE` 方法。 +Reference method `FieldE`. ## FieldE -取 `map` 或 `struct` 的字段值,返回 `interface{}`。 +Return the field value from map/struct, `interface{}`. ```go // map @@ -29,12 +29,41 @@ cvt.FieldE(struct{ }{"Hello", 18}, "B") // 18 ``` -`Field` 与其他方法结合使用: +Combine with other methods: ```go cvt.Int(cvt.Field(map[int]interface{}{123: "112233"}, 123)) // 112233 ``` +## Len +return size of string, slice, array or map. + +```go +cvt.Len("Hello") // 5 +cvt.Len([]int{1, 2, 3}) // 3 +cvt.Len([]interface{}{1, "2", 3.0}}) // 3 +cvt.Len(map[int]interface{}{1: 1, 2: 2}) // 2 +``` + +## IsEmpty +checks value for empty state. + +```go +cvt.IsEmpty("") // true +cvt.IsEmpty("123") // false +cvt.IsEmpty(nil) // true +cvt.IsEmpty(true) // false +cvt.IsEmpty(false) // true +cvt.IsEmpty(0) // true +cvt.IsEmpty(1) // false +cvt.IsEmpty(180) // false +cvt.IsEmpty(1.23) // false +cvt.IsEmpty([]bool{}) // true +cvt.IsEmpty([]int{1, 2}) // false +cvt.IsEmpty(map[int]interface{}(nil)) // true +cvt.IsEmpty(map[string]string{"1": "1", "2": "2"}) // false +``` + > 更多示例请看单元测试:`cvte_test.go`