diff --git a/README.md b/README.md index 1ded254..144ffaa 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,8 @@ import "github.com/duke-git/lancet/v2/convertor" - **DeepClone** : creates a deep copy of passed item, can't clone unexported field of struct. [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor.md#DeepClone)] [[play](https://go.dev/play/p/j4DP5dquxnk)] +- **CopyProperties** : copies each field from the source struct into the destination struct. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor.md#CopyProperties)] ### 5. Cryptor package is for data encryption and decryption. @@ -606,12 +608,24 @@ import "github.com/duke-git/lancet/v2/maputil" - **Filter** : iterates over map, return a new map contains all key and value pairs pass the predicate function. [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Filter)] [[play](https://go.dev/play/p/fSvF3wxuNG7)] +- **FilterByKeys** : iterates over map, return a new map whose keys are all given keys + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#FilterByKeys)] +- **FilterByValues** : iterates over map, return a new map whose values are all given values. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#FilterByValues)] +- **OmitBy** : the opposite of Filter, removes all the map elements for which the predicate function returns true. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#OmitBy)] +- **OmitByKeys** : the opposite of FilterByKeys, extracts all the map elements which keys are not omitted. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#OmitByKeys)] +- **OmitByValues** : the opposite of FilterByValues. remov all elements whose value are in the give slice. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#OmitByValues)] - **Intersect** : iterates over maps, return a new map of key and value pairs in all given maps. [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Intersect)] [[play](https://go.dev/play/p/Zld0oj3sjcC)] - **Keys** : returns a slice of the map's keys. [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Keys)] [[play](https://go.dev/play/p/xNB5bTb97Wd)] +- **KeysBy** : creates a slice whose element is the result of function mapper invoked by every map's key. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#KeysBy)] - **Merge** : merge maps, next key will overwrite previous key. [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Merge)] [[play](https://go.dev/play/p/H95LENF1uB-)] @@ -621,6 +635,18 @@ import "github.com/duke-git/lancet/v2/maputil" - **Values** : returns a slice of the map's values. [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Values)] [[play](https://go.dev/play/p/CBKdUc5FTW6)] +- **ValuesBy** : creates a slice whose element is the result of function mapper invoked by every map's value. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#ValuesBy)] +- **MapKeys** : transforms a map to other type map by manipulating it's keys. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#MapKeys)] +- **MapValues** : transforms a map to other type map by manipulating it's values. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#MapValues)] +- **Entries** : transforms a map into array of key/value pairs. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Entries)] +- **FromEntries** : creates a map based on a slice of key/value pairs. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#FromEntries)] +- **Transform** : transform a map to another type map. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#Transform)] - **IsDisjoint** : check two map are disjoint if they have no keys in common. [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil.md#IsDisjoint)] [[play](https://go.dev/play/p/N9qgYg_Ho6f)] @@ -806,6 +832,8 @@ import "github.com/duke-git/lancet/v2/slice" - **Contain** : check if the value is in the slice or not. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Contain)] [[play](https://go.dev/play/p/_454yEHcNjf)] +- **ContainBy** : returns true if predicate function return true. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ContainBy)] - **ContainSubSlice** : check if the slice contain a given subslice or not. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ContainSubSlice)] [[play](https://go.dev/play/p/bcuQ3UT6Sev)] @@ -860,6 +888,8 @@ import "github.com/duke-git/lancet/v2/slice" - **Filter** : iterates over elements of slice, returning an slice of all elements pass the predicate function. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Filter)] [[play](https://go.dev/play/p/SdPna-7qK4T)] +- **FilterMap** : returns a slice which apply both filtering and mapping to the given slice. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FilterMap)] - **Find** : iterates over elements of slice, returning the first one that passes a truth test on predicate function. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Find)] [[play](https://go.dev/play/p/CBKeBoHVLgq)] @@ -872,6 +902,8 @@ import "github.com/duke-git/lancet/v2/slice" - **FlattenDeep** : flattens slice recursive to one level. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FlattenDeep)] [[play](https://go.dev/play/p/yjYNHPyCFaF)] +- **FlatMap** : manipulates a slice and transforms and flattens it to a slice of another type. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#FlatMap)] - **ForEach** : iterates over elements of slice and invokes function for each element. [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice.md#ForEach)] [[play](https://go.dev/play/p/DrPaa4YsHRF)] @@ -1021,6 +1053,8 @@ import "github.com/duke-git/lancet/v2/strutil" - **UpperFirst** : converts the first character of string to upper case. [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#UpperFirst)] [[play](https://go.dev/play/p/sBbBxRbs8MM)] +- **Pad** : pads string on the left and right side if it's shorter than size. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Pad)] - **PadEnd** : pads string with given characters on the right side if it's shorter than limit size. Padding characters are truncated if they exceed size. [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#PadEnd)] [[play](https://go.dev/play/p/9xP8rN0vz--)] @@ -1048,6 +1082,10 @@ import "github.com/duke-git/lancet/v2/strutil" - **Unwrap** : unwrap a given string from anther string. will change source string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#Unwrap)] [[play](https://go.dev/play/p/Ec2q4BzCpG-)] +- **SplitWords** : splits a string into words, word only contains alphabetic characters. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#SplitWords)] +- **WordCount** : return the number of meaningful word of a string, word only contains alphabetic characters. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil.md#WordCount)] ### 19. System package contain some functions about os, runtime, shell command. diff --git a/README_zh-CN.md b/README_zh-CN.md index fa721b5..3d03f8b 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -248,7 +248,8 @@ import "github.com/duke-git/lancet/v2/convertor" - **DeepClone** : 创建一个传入值的深拷贝, 无法克隆结构体的非导出字段。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#DeepClone)] [[play](https://go.dev/play/p/j4DP5dquxnk)] - +- **CopyProperties** : 拷贝不同结构体之间的同名字段。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/convertor_zh-CN.md#CopyProperties)] ### 5. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。 @@ -610,12 +611,24 @@ import "github.com/duke-git/lancet/v2/maputil" - **Filter** : 迭代 map 中的每对 key 和 value,返回 map,其中的 key 和 value 符合 predicate 函数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN.md#Filter)] [[play](https://go.dev/play/p/fSvF3wxuNG7)] +- **FilterByKeys** : 迭代map, 返回一个新map,其key都是给定的key值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#FilterByKeys)] +- **FilterByValues** : 迭代map, 返回一个新map,其value都是给定的value值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#FilterByValues)] +- **OmitBy** : Filter的反向操作, 迭代map中的每对key和value, 删除符合predicate函数的key, value, 返回新map。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#OmitBy)] +- **OmitByKeys** : FilterByKeys的反向操作, 迭代map, 返回一个新map,其key不包括给定的key值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#OmitByKeys)] +- **OmitByValues** : FilterByValues的反向操作, 迭代map, 返回一个新map,其value不包括给定的value值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#OmitByValues)] - **Intersect** : 多个 map 的交集操作。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN.md#Intersect)] [[play](https://go.dev/play/p/Zld0oj3sjcC)] - **Keys** : 返回 map 中所有 key 组成的切片。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN.md#Keys)] [[play](https://go.dev/play/p/xNB5bTb97Wd)] +- **KeysBy** : 创建一个切片,其元素是每个map的key调用mapper函数的结果。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#KeysBy)] - **Merge** : 合并多个 map, 相同的 key 会被之后的 key 覆盖。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN.md#Merge)] [[play](https://go.dev/play/p/H95LENF1uB-)] @@ -625,7 +638,19 @@ import "github.com/duke-git/lancet/v2/maputil" - **Values** : 返回 map 中所有 values 组成的切片 [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN.md#Values)] [[play](https://go.dev/play/p/CBKdUc5FTW6)] -- **IsDisjoint** : 验证两个 map 是否具有不同的 key。 +- **ValuesBy** : 创建一个切片,其元素是每个map的value调用mapper函数的结果。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#ValuesBy)] +- **MapKeys** : 操作map的每个key,然后转为新的map。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#MapKeys)] +- **MapValues** : 操作map的每个value,然后转为新的map。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#MapValues)] +- **Entries** : 将map转换为键/值对切片。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#Entries)] +- **FromEntries** : 基于键/值对的切片创建map。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#FromEntries)] +- **Transform** : 将map转换为其他类型的map。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN#Transform)] +- **IsDisjoint** : 验证两个map是否具有不同的key。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/maputil_zh-CN.md#IsDisjoint)] [[play](https://go.dev/play/p/N9qgYg_Ho6f)] @@ -814,6 +839,8 @@ import "github.com/duke-git/lancet/v2/slice" - **Contain** : 判断slice是否包含value。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Contain)] [[play](https://go.dev/play/p/_454yEHcNjf)] +- **ContainBy** : 根据predicate函数判断切片是否包含某个值。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#ContainBy)] - **ContainSubSlice** : 判断slice是否包含subslice。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#ContainSubSlice)] [[play](https://go.dev/play/p/bcuQ3UT6Sev)] @@ -868,6 +895,8 @@ import "github.com/duke-git/lancet/v2/slice" - **Filter** : 返回切片中通过predicate函数真值测试的所有元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Filter)] [[play](https://go.dev/play/p/SdPna-7qK4T)] +- **FilterMap** : 返回一个将filter和map操作应用于给定切片的切片。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FilterMap)] - **Find** : 遍历切片的元素,返回第一个通过predicate函数真值测试的元素。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#Find)] [[play](https://go.dev/play/p/CBKeBoHVLgq)] @@ -880,6 +909,8 @@ import "github.com/duke-git/lancet/v2/slice" - **FlattenDeep** : 将多维切片递归展平到一层。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FlattenDeep)] [[play](https://go.dev/play/p/yjYNHPyCFaF)] +- **FlatMap** : 将切片转换为其它类型切片。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#FlatMap)] - **ForEach** : 遍历切片的元素并为每个元素调用iteratee函数。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/slice_zh-CN.md#ForEach)] [[play](https://go.dev/play/p/DrPaa4YsHRF)] @@ -1031,6 +1062,8 @@ import "github.com/duke-git/lancet/v2/strutil" - **UpperFirst** : 将字符串的第一个字符转换为大写形式。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#UpperFirst)] [[play](https://go.dev/play/p/sBbBxRbs8MM)] +- **Pad** : 如果字符串长度短于size,则在左右两侧填充字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Pad)] - **PadEnd** : 如果字符串短于限制大小,则在右侧用给定字符填充字符串。 如果填充字符超出大小,它们将被截断。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#PadEnd)] [[play](https://go.dev/play/p/9xP8rN0vz--)] @@ -1058,6 +1091,10 @@ import "github.com/duke-git/lancet/v2/strutil" - **Unwrap** : 从另一个字符串中解开一个给定的字符串。 将更改源字符串。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#Unwrap)] [[play](https://go.dev/play/p/Ec2q4BzCpG-)] +- **SplitWords** : 将字符串拆分为单词,只支持字母字符单词。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#SplitWords)] +- **WordCount** : 返回有意义单词的数量,只支持字母字符单词。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/strutil_zh-CN.md#WordCount)] ### 18. system 包含 os, runtime, shell command 的相关函数。 diff --git a/docs/maputil_zh-CN.md b/docs/maputil_zh-CN.md index 12d5950..84a713d 100644 --- a/docs/maputil_zh-CN.md +++ b/docs/maputil_zh-CN.md @@ -90,7 +90,7 @@ func main() { ### Filter -

迭代map中的每对key和value, 返回符合predicate函数的key, value

+

迭代map中的每对key和value, 返回符合predicate函数的key, value。

函数签名: @@ -135,7 +135,7 @@ func main() { ### FilterByKeys -

迭代map, 返回一个新map,其key都是给定的key值.

+

迭代map, 返回一个新map,其key都是给定的key值。

函数签名: @@ -174,7 +174,7 @@ func main() { ### FilterByValues -

迭代map, 返回一个新map,其value都是给定的value值.

+

迭代map, 返回一个新map,其value都是给定的value值。

函数签名: @@ -213,7 +213,7 @@ func main() { ### OmitBy -

Filter的反向操作, 迭代map中的每对key和value, 删除符合predicate函数的key, value, 返回新map

+

Filter的反向操作, 迭代map中的每对key和value, 删除符合predicate函数的key, value, 返回新map。

函数签名: @@ -255,7 +255,7 @@ func main() { ### OmitByKeys -

FilterByKeys的反向操作, 迭代map, 返回一个新map,其key不包括给定的key值.

+

FilterByKeys的反向操作, 迭代map, 返回一个新map,其key不包括给定的key值。

函数签名: @@ -294,7 +294,7 @@ func main() { ### OmitByValues -

FilterByValues的反向操作, 迭代map, 返回一个新map,其value不包括给定的value值.

+

FilterByValues的反向操作, 迭代map, 返回一个新map,其value不包括给定的value值。

函数签名: