diff --git a/README.md b/README.md index 2134fae..c23abd6 100644 --- a/README.md +++ b/README.md @@ -281,6 +281,7 @@ import "github.com/duke-git/lancet/v2/convertor" [[play](https://go.dev/play/p/oZujoB5Sgg5)] - **ToInterface** : converts reflect value to its interface type. [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor.md#ToInterface)] + [[play](https://go.dev/play/p/syqw0-WG7Xd)] ### 6. Cryptor package is for data encryption and decryption. @@ -405,6 +406,7 @@ import "github.com/duke-git/lancet/v2/datetime" [[play](https://go.dev/play/p/nT1heB1KUUK)] - **AddYear** : add or sub year to the time. [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#AddYear)] + [[play](https://go.dev/play/p/MqW2ujnBx10)] - **BeginOfMinute** : return the date time at the begin of minute of specific date. [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#BeginOfMinute)] [[play](https://go.dev/play/p/ieOLVJ9CiFT)] @@ -488,6 +490,8 @@ import "github.com/duke-git/lancet/v2/datetime" [[play](https://go.dev/play/p/mkhOHQkdeA2)] - **IsLeapYear** : check if param `year` is leap year or not. [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime.md#IsLeapYear)] + [[play](https://go.dev/play/p/xS1eS2ejGew)] + ### 8. Datastructure package constains some common data structure. eg. list, linklist, stack, queue, set, tree, graph. @@ -765,7 +769,7 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/N9qgYg_Ho6f)] - **Percent** : calculate the percentage of value to total. [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#Percent)] - [[play](https://go.dev/play/p/QQM9B13coSP)] + [[play](https://go.dev/play/p/s0NdFCtwuyd)] - **RoundToFloat** : round up to n decimal places for float64. [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#RoundToFloat)] [[play](https://go.dev/play/p/ghyb528JRJL)] @@ -795,8 +799,10 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/Rdd8UTHZJ7u)] - **GCD** : return greatest common divisor (GCD) of integers. [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#GCD)] + [[play](https://go.dev/play/p/CiEceLSoAKB)] - **LCM** : return Least Common Multiple (LCM) of integers. [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil.md#LCM)] + [[play](https://go.dev/play/p/EjcZxfY7G_g)] ### 14. Netutil package contains functions to get net information and send http request. @@ -1359,10 +1365,13 @@ import "github.com/duke-git/lancet/v2/strutil" [[play](https://go.dev/play/p/qZo4lV2fomB)] - **ReplaceWithMap** : returns a copy of `str`, which is replaced by a map in unordered way, case-sensitively. [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#ReplaceWithMap)] + [[play](https://go.dev/play/p/h3t7CNj2Vvu)] - **Trim** : strips whitespace (or other characters) from the beginning and end of a string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Trim)] + [[play](https://go.dev/play/p/Y0ilP0NRV3j)] - **SplitAndTrim** : splits string `str` by a string `delimiter` to a slice, and calls Trim to every element of slice. [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SplitAndTrim)] + [[play](https://go.dev/play/p/ZNL6o4SkYQ7)] ### 21. System package contain some functions about os, runtime, shell command. diff --git a/README_zh-CN.md b/README_zh-CN.md index eba0b80..2bf93a8 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -280,6 +280,7 @@ import "github.com/duke-git/lancet/v2/convertor" [[play](https://go.dev/play/p/oZujoB5Sgg5)] - **ToInterface** : 将反射值转换成对应的 interface 类型。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#ToInterface)] + [[play](https://go.dev/play/p/syqw0-WG7Xd)] ### 6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。 @@ -404,6 +405,7 @@ import "github.com/duke-git/lancet/v2/datetime" [[play](https://go.dev/play/p/nT1heB1KUUK)] - **AddYear** : 将日期加/减分年数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#AddYear)] + [[play](https://go.dev/play/p/MqW2ujnBx10)] - **BeginOfMinute** : 返回指定时间的分钟开始时间。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#BeginOfMinute)] [[play](https://go.dev/play/p/ieOLVJ9CiFT)] @@ -479,14 +481,15 @@ import "github.com/duke-git/lancet/v2/datetime" - **ToFormat** : 返回格式'yyyy-mm-dd hh:mm:ss'的日期字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#ToFormat)] [[play](https://go.dev/play/p/VkW08ZOaXPZ)] -- **ToFormatForTpl** : 返回tpl格式指定的日期字符串。 +- **ToFormatForTpl** : 返回 tpl 格式指定的日期字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#ToFormatForTpl)] [[play](https://go.dev/play/p/nyXxXcQJ8L5)] -- **ToIso8601** : 返回iso8601日期字符串。 +- **ToIso8601** : 返回 iso8601 日期字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#ToIso8601)] [[play](https://go.dev/play/p/mkhOHQkdeA2)] - **IsLeapYear** :验证是否是闰年。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/datetime_zh-CN.md#IsLeapYear)] + [[play](https://go.dev/play/p/xS1eS2ejGew)] ### 8. datastructure 包含一些普通的数据结构实现。例如:list, linklist, stack, queue, set, tree, graph. @@ -764,7 +767,7 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/N9qgYg_Ho6f)] - **Percent** : 计算百分比,可以指定保留 n 位小数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#Percent)] - [[play](https://go.dev/play/p/QQM9B13coSP)] + [[play](https://go.dev/play/p/s0NdFCtwuyd)] - **RoundToFloat** : 四舍五入,保留 n 位小数,返回 float64。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#RoundToFloat)] [[play](https://go.dev/play/p/ghyb528JRJL)] @@ -794,8 +797,10 @@ import "github.com/duke-git/lancet/v2/mathutil" [[play](https://go.dev/play/p/Rdd8UTHZJ7u)] - **GCD** : 求最大公约数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#GCD)] + [[play](https://go.dev/play/p/CiEceLSoAKB)] - **LCM** : 求最小公倍数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/mathutil_zh-CN.md#LCM)] + [[play](https://go.dev/play/p/EjcZxfY7G_g)] ### 14. netutil 网络包支持获取 ip 地址,发送 http 请求。 @@ -1140,7 +1145,7 @@ import "github.com/duke-git/lancet/v2/slice" [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#KeyBy)] [[play](https://go.dev/play/p/uXod2LWD1Kg)] -### 18. Stream流,该包仅验证简单的stream实现,功能有限。 +### 18. Stream 流,该包仅验证简单的 stream 实现,功能有限。 ```go import "github.com/duke-git/lancet/v2/stream" @@ -1199,11 +1204,12 @@ import "github.com/duke-git/lancet/v2/stream" - **Reduce** : 使用关联累加函数对 stream 的元素执行 reduce 操作,并 reduce 操作结果(如果有)。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Reduce)] [[play](https://go.dev/play/p/6uzZjq_DJLU)] -- **FindFirst** : 返回此 stream的第一个元素,如果 stream 为空,则返回零值和 false。 +- **FindFirst** : 返回此 stream 的第一个元素,如果 stream 为空,则返回零值和 false。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#FindFirst)] [[play](https://go.dev/play/p/9xEf0-6C1e3)] -- **FindLast** : 返回此 stream的最后一个元素,如果 stream 为空,则返回零值和 false。 +- **FindLast** : 返回此 stream 的最后一个元素,如果 stream 为空,则返回零值和 false。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#FindLast)] + [[play](https://go.dev/play/p/WZD2rDAW-2h)] - **Max** : 根据提供的 less 函数返回 stream 的最大元素。less 函数: a > b [[doc](https://github.com/duke-git/lancet/blob/main/docs/stream_zh-CN.md#Max)] [[play](https://go.dev/play/p/fm-1KOPtGzn)] @@ -1361,10 +1367,13 @@ import "github.com/duke-git/lancet/v2/strutil" [[play](https://go.dev/play/p/qZo4lV2fomB)] - **ReplaceWithMap** : 返回 string 的副本,以无序的方式被 map 替换,区分大小写。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#ReplaceWithMap)] + [[play](https://go.dev/play/p/h3t7CNj2Vvu)] - **Trim** : 从字符串的开头和结尾去除空格(或其他字符)。 可选参数 characterMask 指定额外的剥离字符。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Trim)] -- **SplitAndTrim** : 将字符串str按字符串delimiter拆分为一个切片,并对该数组的每个元素调用Trim。忽略Trim后为空的元素。 + [[play](https://go.dev/play/p/Y0ilP0NRV3j)] +- **SplitAndTrim** : 将字符串 str 按字符串 delimiter 拆分为一个切片,并对该数组的每个元素调用 Trim。忽略 Trim 后为空的元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SplitAndTrim)] + [[play](https://go.dev/play/p/ZNL6o4SkYQ7)] ### 21. system 包含 os, runtime, shell command 的相关函数。 diff --git a/convertor/convertor.go b/convertor/convertor.go index ce6cb3f..2a46929 100644 --- a/convertor/convertor.go +++ b/convertor/convertor.go @@ -349,7 +349,7 @@ func CopyProperties[T, U any](dst T, src U) error { } // ToInterface converts reflect value to its interface type. -// Play: todo +// Play: https://go.dev/play/p/syqw0-WG7Xd func ToInterface(v reflect.Value) (value interface{}, ok bool) { if v.IsValid() && v.CanInterface() { return v.Interface(), true diff --git a/datetime/datetime.go b/datetime/datetime.go index ad3391b..9cd163e 100644 --- a/datetime/datetime.go +++ b/datetime/datetime.go @@ -73,7 +73,7 @@ func AddDay(t time.Time, day int64) time.Time { } // AddYear add or sub year to the time. -// Play: todo +// Play: https://go.dev/play/p/MqW2ujnBx10 func AddYear(t time.Time, year int64) time.Time { return t.Add(365 * 24 * time.Hour * time.Duration(year)) } @@ -226,7 +226,7 @@ func EndOfYear(t time.Time) time.Time { } // IsLeapYear check if param year is leap year or not. -// Play: todo +// Play: https://go.dev/play/p/xS1eS2ejGew func IsLeapYear(year int) bool { return year%4 == 0 && (year%100 != 0 || year%400 == 0) } diff --git a/docs/datetime.md b/docs/datetime.md index b6f80c9..f221a40 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -224,10 +224,10 @@ import ( func main() { now := time.Now() - after1Year := AddYear(now, 1) + after1Year := datetime.AddYear(now, 1) diff1 := after1Year.Sub(now) - before1Year := AddYear(now, -1) + before1Year := datetime.AddYear(now, -1) diff2 := before1Year.Sub(now) fmt.Println(diff1) diff --git a/docs/datetime_zh-CN.md b/docs/datetime_zh-CN.md index c7b892c..1d5a1bc 100644 --- a/docs/datetime_zh-CN.md +++ b/docs/datetime_zh-CN.md @@ -223,10 +223,10 @@ import ( func main() { now := time.Now() - after1Year := AddYear(now, 1) + after1Year := datetime.AddYear(now, 1) diff1 := after1Year.Sub(now) - before1Year := AddYear(now, -1) + before1Year := datetime.AddYear(now, -1) diff2 := before1Year.Sub(now) fmt.Println(diff1) @@ -1103,7 +1103,6 @@ func main() { } ``` - ### IsLeapYear
验证是否是闰年。
diff --git a/docs/mathutil.md b/docs/mathutil.md index de069c2..0520eb6 100644 --- a/docs/mathutil.md +++ b/docs/mathutil.md @@ -365,9 +365,9 @@ import ( ) func main() { - result1 := Percent(1, 2, 2) - result2 := Percent(0.1, 0.3, 2) - result3 := Percent(-30305, 408420, 2) + result1 := mathutil.Percent(1, 2, 2) + result2 := mathutil.Percent(0.1, 0.3, 2) + result3 := mathutil.Percent(-30305, 408420, 2) fmt.Println(result1) fmt.Println(result2) diff --git a/docs/mathutil_zh-CN.md b/docs/mathutil_zh-CN.md index 0b53d7e..972e178 100644 --- a/docs/mathutil_zh-CN.md +++ b/docs/mathutil_zh-CN.md @@ -365,9 +365,9 @@ import ( ) func main() { - result1 := Percent(1, 2, 2) - result2 := Percent(0.1, 0.3, 2) - result3 := Percent(-30305, 408420, 2) + result1 := mathutil.Percent(1, 2, 2) + result2 := mathutil.Percent(0.1, 0.3, 2) + result3 := mathutil.Percent(-30305, 408420, 2) fmt.Println(result1) fmt.Println(result2) diff --git a/docs/stream.md b/docs/stream.md index 20ee721..2c0c7d5 100644 --- a/docs/stream.md +++ b/docs/stream.md @@ -687,7 +687,7 @@ import ( ) func main() { - original := FromSlice([]int{3, 2, 1}) + original := stream.FromSlice([]int{3, 2, 1}) result, ok := original.FindLast() diff --git a/docs/stream_zh-CN.md b/docs/stream_zh-CN.md index ad68b5e..390162e 100644 --- a/docs/stream_zh-CN.md +++ b/docs/stream_zh-CN.md @@ -687,7 +687,7 @@ import ( ) func main() { - original := FromSlice([]int{3, 2, 1}) + original := stream.FromSlice([]int{3, 2, 1}) result, ok := original.FindLast() diff --git a/mathutil/mathutil.go b/mathutil/mathutil.go index c2ecfb2..a8e46c9 100644 --- a/mathutil/mathutil.go +++ b/mathutil/mathutil.go @@ -55,7 +55,7 @@ func Factorial(x uint) uint { } // Percent calculate the percentage of value to total. -// Play: https://go.dev/play/p/QQM9B13coSP +// Play: https://go.dev/play/p/s0NdFCtwuyd func Percent(val, total float64, n int) float64 { if total == 0 { return float64(0) @@ -258,7 +258,7 @@ func IsPrime(n int) bool { } // GCD return greatest common divisor (GCD) of integers. -// Play: todo +// Play: https://go.dev/play/p/CiEceLSoAKB func GCD[T constraints.Integer](integers ...T) T { result := integers[0] @@ -283,7 +283,7 @@ func gcd[T constraints.Integer](a, b T) T { } // LCM return Least Common Multiple (LCM) of integers. -// Play: todo +// Play: https://go.dev/play/p/EjcZxfY7G_g func LCM[T constraints.Integer](integers ...T) T { result := integers[0] diff --git a/stream/stream.go b/stream/stream.go index cc6b471..415cc2a 100644 --- a/stream/stream.go +++ b/stream/stream.go @@ -296,7 +296,7 @@ func (s stream[T]) FindFirst() (T, bool) { } // FindLast returns the last element of this stream and true, or zero value and false if the stream is empty. -// Play: https://go.dev/play/p/9xEf0-6C1e3 +// Play: https://go.dev/play/p/WZD2rDAW-2h func (s stream[T]) FindLast() (T, bool) { var result T diff --git a/strutil/string.go b/strutil/string.go index 947a6b1..8df7d09 100644 --- a/strutil/string.go +++ b/strutil/string.go @@ -448,7 +448,7 @@ func IndexOffset(str string, substr string, idxFrom int) int { // ReplaceWithMap returns a copy of `str`, // which is replaced by a map in unordered way, case-sensitively. -// Play: todo +// Play: https://go.dev/play/p/h3t7CNj2Vvu func ReplaceWithMap(str string, replaces map[string]string) string { for k, v := range replaces { str = strings.ReplaceAll(str, k, v) @@ -460,6 +460,7 @@ func ReplaceWithMap(str string, replaces map[string]string) string { // SplitAndTrim splits string `str` by a string `delimiter` to a slice, // and calls Trim to every element of this slice. It ignores the elements // which are empty after Trim. +// Play: https://go.dev/play/p/ZNL6o4SkYQ7 func SplitAndTrim(str, delimiter string, characterMask ...string) []string { result := make([]string, 0) @@ -490,6 +491,7 @@ var ( // Trim strips whitespace (or other characters) from the beginning and end of a string. // The optional parameter `characterMask` specifies the additional stripped characters. +// Play: https://go.dev/play/p/Y0ilP0NRV3j func Trim(str string, characterMask ...string) string { trimChars := DefaultTrimChars