Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
shockerli committed Nov 30, 2024
1 parent 92ba89c commit 147e4a4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
17 changes: 17 additions & 0 deletions doc/content/en/type/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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`
28 changes: 28 additions & 0 deletions doc/content/en/type/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
17 changes: 17 additions & 0 deletions doc/content/zh-cn/type/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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`
35 changes: 32 additions & 3 deletions doc/content/zh-cn/type/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`

0 comments on commit 147e4a4

Please sign in to comment.