mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
Compare commits
16 Commits
4037b96cc4
...
b698fec50f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b698fec50f | ||
|
|
b38bb66b34 | ||
|
|
bdfdeaf496 | ||
|
|
172c44c07a | ||
|
|
534263eb08 | ||
|
|
a25b1ac7e3 | ||
|
|
d84f9777ea | ||
|
|
f9caaf8063 | ||
|
|
f198711d1c | ||
|
|
19378ca4d1 | ||
|
|
71c7733eb0 | ||
|
|
20786c360b | ||
|
|
51fafa110e | ||
|
|
07fc453b74 | ||
|
|
b309044981 | ||
|
|
541e6d4ea3 |
36
README.md
36
README.md
@@ -4,7 +4,7 @@
|
||||
<br/>
|
||||
|
||||

|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||
@@ -19,7 +19,7 @@
|
||||
Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js.
|
||||
</p>
|
||||
|
||||
English | [简体中文](./README_zh-CN.md)
|
||||
## <a href="https://www.golancet.cn/en/" target="_blank"> Website</a> | [简体中文](./README_zh-CN.md)
|
||||
|
||||
## Feature
|
||||
|
||||
@@ -1325,6 +1325,9 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
- **<big>Join</big>** : join the slice item with specify separator.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Join)]
|
||||
[[play](https://go.dev/play/p/huKzqwNDD7V)]
|
||||
- **<big>Partition</big>** : partition all slice elements with the evaluation of the given predicate functions.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Partition)]
|
||||
[[play](https://go.dev/play/p/lkQ3Ri2NQhV)]
|
||||
|
||||
<h3 id="stream"> 19. Stream package implements a sequence of elements supporting sequential and operations. this package is an experiment to explore if stream in go can work as the way java does. its function is very limited. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1826,6 +1829,33 @@ import "github.com/duke-git/lancet/v2/validator"
|
||||
- **<big>IsPrintable</big>** : checks if string is all printable chars.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsPrintable)]
|
||||
[[play](https://go.dev/play/p/Pe1FE2gdtTP)]
|
||||
- **<big>IsBin</big>** : check if a give string is a valid binary value or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsBin)]
|
||||
[[play](https://go.dev/play/p/ogPeg2XJH4P)]
|
||||
- **<big>IsHex</big>** : check if a give string is a valid hexadecimal value or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsHex)]
|
||||
[[play](https://go.dev/play/p/M2qpHbEwmm7)]
|
||||
- **<big>IsBase64URL</big>** : check if a give string is a valid URL-safe Base64 encoded string.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsBase64URL)]
|
||||
[[play](https://go.dev/play/p/vhl4mr8GZ6S)]
|
||||
- **<big>IsJWT</big>** : check if a give string is a valid JSON Web Token (JWT).
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsJWT)]
|
||||
[[play](https://go.dev/play/p/R6Op7heJbKI)]
|
||||
- **<big>IsVisa</big>** : check if a give string is a valid visa card nubmer or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsVisa)]
|
||||
[[play](https://go.dev/play/p/SdS2keOyJsl)]
|
||||
- **<big>IsMasterCard</big>** : check if a give string is a valid master card nubmer or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsMasterCard)]
|
||||
[[play](https://go.dev/play/p/CwWBFRrG27b)]
|
||||
- **<big>IsAmericanExpress</big>** : check if a give string is a valid american expression card nubmer or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsAmericanExpress)]
|
||||
[[play](https://go.dev/play/p/HIDFpcOdpkd)]
|
||||
- **<big>IsUnionPay</big>** : check if a give string is a valid union pay nubmer or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsUnionPay)]
|
||||
[[play](https://go.dev/play/p/CUHPEwEITDf)]
|
||||
- **<big>IsChinaUnionPay</big>** : check if a give string is a valid china union pay nubmer or not.
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsChinaUnionPay)]
|
||||
[[play](https://go.dev/play/p/yafpdxLiymu)]
|
||||
|
||||
<h3 id="xerror"> 25. Xerror package implements helpers for errors. <a href="#index">index</a></h3>
|
||||
|
||||
@@ -1892,7 +1922,7 @@ Hello, I am a software developer and have been engaged in development work for 1
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
*Donated funds will be used to maintain this website and pay for cloud server costs. Or just buy me a cup of ☕️ when I'm sleepy writing code.*
|
||||
*Donated funds will be used to maintain [lancet](https://www.golancet.cn/en/) website and pay for cloud server costs. Or just buy me a cup of ☕️ when I'm sleepy writing code.*
|
||||
|
||||
|
||||
## Contributors
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<br/>
|
||||
|
||||

|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||
@@ -18,7 +18,7 @@
|
||||
lancet(柳叶刀)是一个全面、高效、可复用的go语言工具函数库。 lancet受到了java apache common包和lodash.js的启发。
|
||||
</p>
|
||||
|
||||
简体中文 | [English](./README.md)
|
||||
## <a href="https://www.golancet.cn/" target="_blank">官网</a> | [English](./README.md)
|
||||
|
||||
## 特性
|
||||
|
||||
@@ -1329,6 +1329,9 @@ import "github.com/duke-git/lancet/v2/slice"
|
||||
- **<big>Join</big>** : 用指定的分隔符链接切片元素。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Join)]
|
||||
[[play](https://go.dev/play/p/huKzqwNDD7V)]
|
||||
- **<big>Partition</big>** : 根据给定的predicate判断函数分组切片元素。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Partition)]
|
||||
[[play](https://go.dev/play/p/lkQ3Ri2NQhV)]
|
||||
|
||||
<h3 id="stream"> 19. stream 流,该包仅验证简单的 stream 实现,功能有限。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1572,7 +1575,6 @@ import "github.com/duke-git/lancet/v2/strutil"
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#RemoveWhiteSpace)]
|
||||
[[play](https://go.dev/play/p/HzLC9vsTwkf)]
|
||||
|
||||
|
||||
<h3 id="system"> 22. system 包含 os, runtime, shell command 的相关函数。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
```go
|
||||
@@ -1833,6 +1835,33 @@ import "github.com/duke-git/lancet/v2/validator"
|
||||
- **<big>IsPrintable</big>** : 检查字符串是否全部为可打印字符。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsPrintable)]
|
||||
[[play](https://go.dev/play/p/Pe1FE2gdtTP)]
|
||||
- **<big>IsBin</big>** : 检查字符串是否是有效的二进制数。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsBin)]
|
||||
[[play](https://go.dev/play/p/ogPeg2XJH4P)]
|
||||
- **<big>IsHex</big>** : 检查字符串是否是有效的十六进制数。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsHex)]
|
||||
[[play](https://go.dev/play/p/M2qpHbEwmm7)]
|
||||
- **<big>IsBase64URL</big>** : 检查字符串是否是有效的 base64 url。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsBase64URL)]
|
||||
[[play](https://go.dev/play/p/vhl4mr8GZ6S)]
|
||||
- **<big>IsJWT</big>** : 检查字符串是否是有效的 JSON Web Token (JWT)。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/validator.md#IsJWT)]
|
||||
[[play](https://go.dev/play/p/R6Op7heJbKI)]
|
||||
- **<big>IsVisa</big>** : 检查字符串是否是有效的 visa 卡号。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsVisa)]
|
||||
[[play](https://go.dev/play/p/SdS2keOyJsl)]
|
||||
- **<big>IsMasterCard</big>** : 检查字符串是否是有效的 MasterCard 卡号。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsMasterCard)]
|
||||
[[play](https://go.dev/play/p/CwWBFRrG27b)]
|
||||
- **<big>IsAmericanExpress</big>** : 检查字符串是否是有效的 American Express 卡号。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsAmericanExpress)]
|
||||
[[play](https://go.dev/play/p/HIDFpcOdpkd)]
|
||||
- **<big>IsUnionPay</big>** : 检查字符串是否是有效的美国银联卡号。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsUnionPay)]
|
||||
[[play](https://go.dev/play/p/CUHPEwEITDf)]
|
||||
- **<big>IsChinaUnionPay</big>** : 检查字符串是否是有效的中国银联卡号。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/validator.md#IsChinaUnionPay)]
|
||||
[[play](https://go.dev/play/p/yafpdxLiymu)]
|
||||
|
||||
<h3 id="xerror"> 25. xerror 包实现一些错误处理函数。 <a href="#index">回到目录</a></h3>
|
||||
|
||||
@@ -1855,7 +1884,7 @@ import "github.com/duke-git/lancet/v2/xerror"
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Wrap)]
|
||||
[[play](https://go.dev/play/p/RpjJ5u5sc97)]
|
||||
- **<big>XError_Unwrap</big>** : 解构 XEerror 为 error 对象。适配 github.com/pkg/errors。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Unwrap)]
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_Unwrap)
|
||||
[[play](https://go.dev/play/p/VUXJ8BST4c6)]
|
||||
- **<big>XError_With</big>** : 添加与 XError 对象的键和值。
|
||||
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/xerror.md#XError_With)]
|
||||
@@ -1888,7 +1917,7 @@ import "github.com/duke-git/lancet/v2/xerror"
|
||||
|
||||
## 赞助
|
||||
|
||||
您好,我是一名软件开发者,从事开发工作 13 年。热爱软件开源。并愿意为此付出精力。是开源项目lancet的作者。Lancet 自两年前开源发布以来,已有超过 1000 个内外部项目使用。lancet一直会对所有用户免费。您的支持是对我继续奋斗的有力鼓励。谢谢! 微信扫描以下二维码或点击以下赞助按钮发起赞助。
|
||||
您好,我是一名软件开发者,从事开发工作 13 年。热爱软件开源。并愿意为此付出精力。是开源项目 lancet 的作者。Lancet 自两年前开源发布以来,已有超过 1000 个内外部项目使用。lancet 一直会对所有用户免费。您的支持是对我继续奋斗的有力鼓励。谢谢! 微信扫描以下二维码或点击以下赞助按钮发起赞助。
|
||||
|
||||
<div style="position: relative;display: inline-block;">
|
||||
<img src="./docs/public/wechat_pay.png" width="260" height="260"/>
|
||||
@@ -1898,12 +1927,11 @@ import "github.com/duke-git/lancet/v2/xerror"
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
*捐赠的资金将用于后续lancet官网的维护和云服务器的费用支付。或者当我写代码困倦时,给我买杯 ☕️。*
|
||||
|
||||
_捐赠的资金将用于后续[lancet](https://www.golancet.cn/)官网的维护和云服务器的费用支付。或者当我写代码困倦时,给我买杯 ☕️。_
|
||||
|
||||
## 贡献者
|
||||
|
||||
感谢所有为lancet贡献过代码的人!
|
||||
感谢所有为 lancet 贡献过代码的人!
|
||||
|
||||
<a href="https://github.com/duke-git/lancet/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=duke-git/lancet" />
|
||||
|
||||
@@ -99,7 +99,7 @@ func (c *cloner) cloneArray(v reflect.Value) reflect.Value {
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
val := c.clone(v.Index(i))
|
||||
|
||||
if val.IsValid() {
|
||||
if !val.IsValid() {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -337,6 +337,7 @@ func TestDeepClone(t *testing.T) {
|
||||
Nil: nil,
|
||||
// unexported: "can't be cloned",
|
||||
},
|
||||
[]interface{}{1, &Struct{Str: "test"}, Struct{Str: "test2"}},
|
||||
}
|
||||
|
||||
for i, item := range cases {
|
||||
|
||||
@@ -39,7 +39,7 @@ export const slugify = (str: string): string =>
|
||||
|
||||
export const commonConfig = defineConfig({
|
||||
title: 'Lancet',
|
||||
appearance: 'dark',
|
||||
appearance: true,
|
||||
|
||||
markdown: {
|
||||
theme: {
|
||||
@@ -83,7 +83,7 @@ export const commonConfig = defineConfig({
|
||||
|
||||
footer: {
|
||||
copyright: 'Copyright © 2023-present Duke Du',
|
||||
message: 'Released under the MIT License.',
|
||||
message: '备案号: 京ICP备2023022770号',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -27,7 +27,7 @@ outline: deep
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
line-height: 40px;
|
||||
background: #ecefff;
|
||||
background: #10b981;
|
||||
border: 1px solid;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
@@ -91,6 +91,7 @@ import (
|
||||
- [Without](#Without)
|
||||
- [KeyBy](#KeyBy)
|
||||
- [Join](#Join)
|
||||
- [Partition](#Partition)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -2452,3 +2453,39 @@ func main() {
|
||||
// 1-2-3-4-5
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="Partition">Partition</span>
|
||||
|
||||
<p>根据给定的predicate判断函数分组切片元素。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/lkQ3Ri2NQhV)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
nums := []int{1, 2, 3, 4, 5}
|
||||
|
||||
result1 := slice.Partition(nums)
|
||||
result2 := slice.Partition(nums, func(n int) bool { return n%2 == 0 })
|
||||
result3 := slice.Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
|
||||
// Output:
|
||||
// [[1 2 3 4 5]]
|
||||
// [[2 4] [1 3 5]]
|
||||
// [[1 2] [3 4] [5]]
|
||||
}
|
||||
```
|
||||
@@ -55,10 +55,18 @@ import (
|
||||
- [IsZeroValue](#IsZeroValue)
|
||||
- [IsGBK](#IsGBK)
|
||||
- [IsPrintable](#IsPrintable)
|
||||
- [IsBin](#IsBin)
|
||||
- [IsHex](#IsHex)
|
||||
- [IsBase64URL](#IsBase64URL)
|
||||
- [IsJWT](#IsJWT)
|
||||
- [IsVisa](#IsVisa)
|
||||
- [IsMasterCard](#IsMasterCard)
|
||||
- [IsAmericanExpress](#IsAmericanExpress)
|
||||
- [IsUnionPay](#IsUnionPay)
|
||||
- [IsChinaUnionPay](#IsChinaUnionPay)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
|
||||
## 文档
|
||||
|
||||
### <span id="ContainChinese">ContainChinese</span>
|
||||
@@ -71,7 +79,7 @@ import (
|
||||
func ContainChinese(s string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/7DpU0uElYeM)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/7DpU0uElYeM)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -105,7 +113,7 @@ func main() {
|
||||
func ContainLetter(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/lqFD04Yyewp)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/lqFD04Yyewp)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -139,7 +147,7 @@ func main() {
|
||||
func ContainLower(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Srqi1ItvnAA)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Srqi1ItvnAA)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -173,7 +181,7 @@ func main() {
|
||||
func ContainUpper(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CmWeBEk27-z)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CmWeBEk27-z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -207,7 +215,7 @@ func main() {
|
||||
func IsAlpha(s string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/7Q5sGOz2izQ)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/7Q5sGOz2izQ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -241,7 +249,7 @@ func main() {
|
||||
func IsAllUpper(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ZHctgeK1n4Z)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ZHctgeK1n4Z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -275,7 +283,7 @@ func main() {
|
||||
func IsAllLower(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GjqCnOfV6cM)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GjqCnOfV6cM)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -309,7 +317,7 @@ func main() {
|
||||
func IsASCII(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/hfQNPLX0jNa)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/hfQNPLX0jNa)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -349,7 +357,7 @@ func main() {
|
||||
func IsBase64(base64 string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/sWHEySAt6hl)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/sWHEySAt6hl)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -380,7 +388,7 @@ func main() {
|
||||
func IsChineseMobile(mobileNum string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GPYUlGTOqe3)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GPYUlGTOqe3)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -411,7 +419,7 @@ func main() {
|
||||
func IsChineseIdNum(id string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/d8EWhl2UGDF)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/d8EWhl2UGDF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -442,7 +450,7 @@ func main() {
|
||||
func IsChinesePhone(phone string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/RUD_-7YZJ3I)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/RUD_-7YZJ3I)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -473,7 +481,7 @@ func main() {
|
||||
func IsCreditCard(creditCart string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/sNwwL6B0-v4)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/sNwwL6B0-v4)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -504,7 +512,7 @@ func main() {
|
||||
func IsDns(dns string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/jlYApVLLGTZ)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/jlYApVLLGTZ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -538,7 +546,7 @@ func main() {
|
||||
func IsEmail(email string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Os9VaFlT33G)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Os9VaFlT33G)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -569,7 +577,7 @@ func main() {
|
||||
func IsEmptyString(s string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/dpzgUjFnBCX)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/dpzgUjFnBCX)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -603,7 +611,7 @@ func main() {
|
||||
func IsInt(v any) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/eFoIHbgzl-z)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/eFoIHbgzl-z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -640,7 +648,7 @@ func main() {
|
||||
func IsFloat(v any) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/vsyG-sxr99_Z)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/vsyG-sxr99_Z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -677,7 +685,7 @@ func main() {
|
||||
func IsNumber(v any) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/mdJHOAvtsvF)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/mdJHOAvtsvF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -704,7 +712,6 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### <span id="IsIntStr">IsIntStr</span>
|
||||
|
||||
<p>验证字符串是否是可以转换为整数。</p>
|
||||
@@ -715,7 +722,7 @@ func main() {
|
||||
func IsIntStr(s string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/jQRtFv-a0Rk)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/jQRtFv-a0Rk)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -752,7 +759,7 @@ func main() {
|
||||
func IsFloatStr(s string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/LOYwS_Oyl7U)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LOYwS_Oyl7U)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -789,7 +796,7 @@ func main() {
|
||||
func IsNumberStr(s string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/LzaKocSV79u)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LzaKocSV79u)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -826,7 +833,7 @@ func main() {
|
||||
func IsJSON(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/8Kip1Itjiil)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/8Kip1Itjiil)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -863,7 +870,7 @@ func main() {
|
||||
func IsRegexMatch(s, regex string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/z_XeZo_litG)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/z_XeZo_litG)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -884,8 +891,6 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### <span id="IsIp">IsIp</span>
|
||||
|
||||
<p>验证字符串是否是ip地址。</p>
|
||||
@@ -896,7 +901,7 @@ func main() {
|
||||
func IsIp(ipstr string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/FgcplDvmxoD)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/FgcplDvmxoD)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -933,7 +938,7 @@ func main() {
|
||||
func IsIpV4(ipstr string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/zBGT99EjaIu)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/zBGT99EjaIu)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -964,7 +969,7 @@ func main() {
|
||||
func IsIpV6(ipstr string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/AHA0r0AzIdC)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/AHA0r0AzIdC)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -995,7 +1000,7 @@ func main() {
|
||||
func IsStrongPassword(password string, length int) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/QHdVcSQ3uDg)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/QHdVcSQ3uDg)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1026,7 +1031,7 @@ func main() {
|
||||
func IsUrl(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/pbJGa7F98Ka)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/pbJGa7F98Ka)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1061,7 +1066,7 @@ func main() {
|
||||
func IsWeakPassword(password string, length int) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/wqakscZH5gH)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/wqakscZH5gH)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1092,7 +1097,7 @@ func main() {
|
||||
func IsZeroValue(value any) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/UMrwaDCi_t4)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/UMrwaDCi_t4)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1129,7 +1134,7 @@ func main() {
|
||||
func IsGBK(data []byte) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/E2nt3unlmzP)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/E2nt3unlmzP)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1151,7 +1156,6 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### <span id="IsPrintable">IsPrintable</span>
|
||||
|
||||
<p>检查字符串是否全部为可打印字符。</p>
|
||||
@@ -1162,7 +1166,7 @@ func main() {
|
||||
func IsPrintable(str string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Pe1FE2gdtTP)</span></b>
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Pe1FE2gdtTP)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1190,4 +1194,301 @@ func main() {
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
### <span id="IsBin">IsBin</span>
|
||||
|
||||
<p>检查字符串是否是有效的二进制数。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsBin(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ogPeg2XJH4P)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsBin("0101")
|
||||
result2 := validator.IsBin("0b1101")
|
||||
result3 := validator.IsBin("b1101")
|
||||
result4 := validator.IsBin("1201")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsHex">IsHex</span>
|
||||
|
||||
<p>检查字符串是否是有效的十六进制数。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsHex(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/M2qpHbEwmm7)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsHex("0xabcde")
|
||||
result2 := validator.IsHex("0XABCDE")
|
||||
result3 := validator.IsHex("cdfeg")
|
||||
result4 := validator.IsHex("0xcdfeg")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsBase64URL">IsBase64URL</span>
|
||||
|
||||
<p>检查字符串是否是有效的base64 url。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsBase64URL(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/vhl4mr8GZ6S)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ")
|
||||
result2 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ==")
|
||||
result3 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ=")
|
||||
result4 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ===")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsJWT">IsJWT</span>
|
||||
|
||||
<p>检查字符串是否是有效的JSON Web Token (JWT)。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsJWT(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/R6Op7heJbKI)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVzc2FnZSI6IlB1dGluIGlzIGFic29sdXRlIHNoaXQiLCJpYXQiOjE1MTYyMzkwMjJ9.wkLWA5GtCpWdxNOrRse8yHZgORDgf8TpJp73WUQb910")
|
||||
result2 := validator.IsJWT("abc")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsVisa">IsVisa</span>
|
||||
|
||||
<p>检查字符串是否是有效的visa卡号。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsVisa(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/SdS2keOyJsl)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsVisa("4111111111111111")
|
||||
result2 := validator.IsVisa("123")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsMasterCard">IsMasterCard</span>
|
||||
|
||||
<p>检查字符串是否是有效的MasterCard卡号。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsMasterCard(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CwWBFRrG27b)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsMasterCard("5425233430109903")
|
||||
result2 := validator.IsMasterCard("4111111111111111")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsAmericanExpress">IsAmericanExpress</span>
|
||||
|
||||
<p>检查字符串是否是有效的American Express卡号。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsAmericanExpress(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/HIDFpcOdpkd)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsAmericanExpress("342883359122187")
|
||||
result2 := validator.IsAmericanExpress("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsUnionPay">IsUnionPay</span>
|
||||
|
||||
<p>检查字符串是否是有效的美国银联卡号。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsUnionPay(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CUHPEwEITDf)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsUnionPay("6221263430109903")
|
||||
result2 := validator.IsUnionPay("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsChinaUnionPay">IsChinaUnionPay</span>
|
||||
|
||||
<p>检查字符串是否是有效的中国银联卡号。</p>
|
||||
|
||||
<b>函数签名:</b>
|
||||
|
||||
```go
|
||||
func IsChinaUnionPay(v string) bool
|
||||
```
|
||||
|
||||
<b>示例:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/yafpdxLiymu)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsChinaUnionPay("6250941006528599")
|
||||
result2 := validator.IsChinaUnionPay("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
@@ -27,7 +27,7 @@ outline: deep
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
line-height: 40px;
|
||||
background: #ecefff;
|
||||
background: #059669;
|
||||
border: 1px solid;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
@@ -91,6 +91,7 @@ import (
|
||||
- [Without](#Without)
|
||||
- [KeyBy](#KeyBy)
|
||||
- [Join](#Join)
|
||||
- [Partition](#Partition)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -2450,3 +2451,39 @@ func main() {
|
||||
// 1-2-3-4-5
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="Partition">Partition</span>
|
||||
|
||||
<p>Partition all slice elements with the evaluation of the given predicate functions. </p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/lkQ3Ri2NQhV)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
nums := []int{1, 2, 3, 4, 5}
|
||||
|
||||
result1 := slice.Partition(nums)
|
||||
result2 := slice.Partition(nums, func(n int) bool { return n%2 == 0 })
|
||||
result3 := slice.Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
|
||||
// Output:
|
||||
// [[1 2 3 4 5]]
|
||||
// [[2 4] [1 3 5]]
|
||||
// [[1 2] [3 4] [5]]
|
||||
}
|
||||
```
|
||||
@@ -671,7 +671,7 @@ func main() {
|
||||
|
||||
### <span id="UpperSnakeCase">UpperSnakeCase</span>
|
||||
|
||||
<p>Coverts string to upper KEBAB-CASE, non letters and numbers will be ignored.</p>
|
||||
<p>Coverts string to upper snake_case, non letters and numbers will be ignored.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
||||
@@ -55,6 +55,15 @@ import (
|
||||
- [IsZeroValue](#IsZeroValue)
|
||||
- [IsGBK](#IsGBK)
|
||||
- [IsPrintable](#IsPrintable)
|
||||
- [IsBin](#IsBin)
|
||||
- [IsHex](#IsHex)
|
||||
- [IsBase64URL](#IsBase64URL)
|
||||
- [IsJWT](#IsJWT)
|
||||
- [IsVisa](#IsVisa)
|
||||
- [IsMasterCard](#IsMasterCard)
|
||||
- [IsAmericanExpress](#IsAmericanExpress)
|
||||
- [IsUnionPay](#IsUnionPay)
|
||||
- [IsChinaUnionPay](#IsChinaUnionPay)
|
||||
|
||||
<div STYLE="page-break-after: always;"></div>
|
||||
|
||||
@@ -72,7 +81,7 @@ import (
|
||||
func ContainChinese(s string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/7DpU0uElYeM)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/7DpU0uElYeM)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -106,7 +115,7 @@ func main() {
|
||||
func ContainLetter(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/lqFD04Yyewp)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/lqFD04Yyewp)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -140,7 +149,7 @@ func main() {
|
||||
func ContainLower(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Srqi1ItvnAA)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Srqi1ItvnAA)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -174,7 +183,7 @@ func main() {
|
||||
func ContainUpper(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/CmWeBEk27-z)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CmWeBEk27-z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -208,7 +217,7 @@ func main() {
|
||||
func IsAlpha(s string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/7Q5sGOz2izQ)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/7Q5sGOz2izQ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -242,7 +251,7 @@ func main() {
|
||||
func IsAllUpper(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/ZHctgeK1n4Z)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ZHctgeK1n4Z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -276,7 +285,7 @@ func main() {
|
||||
func IsAllLower(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GjqCnOfV6cM)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GjqCnOfV6cM)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -310,7 +319,7 @@ func main() {
|
||||
func IsASCII(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/hfQNPLX0jNa)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/hfQNPLX0jNa)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -350,7 +359,7 @@ func main() {
|
||||
func IsBase64(base64 string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/sWHEySAt6hl)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/sWHEySAt6hl)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -381,7 +390,7 @@ func main() {
|
||||
func IsChineseMobile(mobileNum string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/GPYUlGTOqe3)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/GPYUlGTOqe3)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -412,7 +421,7 @@ func main() {
|
||||
func IsChineseIdNum(id string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/d8EWhl2UGDF)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/d8EWhl2UGDF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -443,7 +452,7 @@ func main() {
|
||||
func IsChinesePhone(phone string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/RUD_-7YZJ3I)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/RUD_-7YZJ3I)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -474,7 +483,7 @@ func main() {
|
||||
func IsCreditCard(creditCart string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/sNwwL6B0-v4)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/sNwwL6B0-v4)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -505,7 +514,7 @@ func main() {
|
||||
func IsDns(dns string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/jlYApVLLGTZ)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/jlYApVLLGTZ)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -539,7 +548,7 @@ func main() {
|
||||
func IsEmail(email string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Os9VaFlT33G)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Os9VaFlT33G)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -570,7 +579,7 @@ func main() {
|
||||
func IsEmptyString(s string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/dpzgUjFnBCX)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/dpzgUjFnBCX)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -604,7 +613,7 @@ func main() {
|
||||
func IsInt(v any) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/eFoIHbgzl-z)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/eFoIHbgzl-z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -641,7 +650,7 @@ func main() {
|
||||
func IsFloat(v any) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/vsyG-sxr99_Z)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/vsyG-sxr99_Z)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -678,7 +687,7 @@ func main() {
|
||||
func IsNumber(v any) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/mdJHOAvtsvF)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/mdJHOAvtsvF)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -715,7 +724,7 @@ func main() {
|
||||
func IsIntStr(s string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/jQRtFv-a0Rk)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/jQRtFv-a0Rk)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -752,7 +761,7 @@ func main() {
|
||||
func IsFloatStr(s string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LOYwS_Oyl7U)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/LOYwS_Oyl7U)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -789,7 +798,7 @@ func main() {
|
||||
func IsNumberStr(s string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/LzaKocSV79u)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/LzaKocSV79u)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -826,7 +835,7 @@ func main() {
|
||||
func IsJSON(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/8Kip1Itjiil)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/8Kip1Itjiil)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -863,7 +872,7 @@ func main() {
|
||||
func IsRegexMatch(s, regex string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/z_XeZo_litG)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/z_XeZo_litG)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -894,7 +903,7 @@ func main() {
|
||||
func IsIp(ipstr string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/FgcplDvmxoD)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/FgcplDvmxoD)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -931,7 +940,7 @@ func main() {
|
||||
func IsIpV4(ipstr string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/zBGT99EjaIu)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/zBGT99EjaIu)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -962,7 +971,7 @@ func main() {
|
||||
func IsIpV6(ipstr string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/AHA0r0AzIdC)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/AHA0r0AzIdC)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -993,7 +1002,7 @@ func main() {
|
||||
func IsStrongPassword(password string, length int) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/QHdVcSQ3uDg)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/QHdVcSQ3uDg)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1024,7 +1033,7 @@ func main() {
|
||||
func IsUrl(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/pbJGa7F98Ka)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/pbJGa7F98Ka)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1059,7 +1068,7 @@ func main() {
|
||||
func IsWeakPassword(password string, length int) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/wqakscZH5gH)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/wqakscZH5gH)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1090,7 +1099,7 @@ func main() {
|
||||
func IsZeroValue(value any) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/UMrwaDCi_t4)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/UMrwaDCi_t4)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1127,7 +1136,7 @@ func main() {
|
||||
func IsGBK(data []byte) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/E2nt3unlmzP)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/E2nt3unlmzP)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1159,7 +1168,7 @@ func main() {
|
||||
func IsPrintable(str string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[运行](https://go.dev/play/p/Pe1FE2gdtTP)</span></b>
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/Pe1FE2gdtTP)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
@@ -1188,3 +1197,300 @@ func main() {
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsBin">IsBin</span>
|
||||
|
||||
<p>Checks if a give string is a valid binary value or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsBin(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/ogPeg2XJH4P)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsBin("0101")
|
||||
result2 := validator.IsBin("0b1101")
|
||||
result3 := validator.IsBin("b1101")
|
||||
result4 := validator.IsBin("1201")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsHex">IsHex</span>
|
||||
|
||||
<p>Checks if a give string is a valid hexadecimal value or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsHex(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/M2qpHbEwmm7)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsHex("0xabcde")
|
||||
result2 := validator.IsHex("0XABCDE")
|
||||
result3 := validator.IsHex("cdfeg")
|
||||
result4 := validator.IsHex("0xcdfeg")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsBase64URL">IsBase64URL</span>
|
||||
|
||||
<p>Checks if a give string is a valid URL-safe Base64 encoded string.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsBase64URL(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/vhl4mr8GZ6S)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ")
|
||||
result2 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ==")
|
||||
result3 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ=")
|
||||
result4 := validator.IsBase64URL("SAGsbG8sIHdvcmxkIQ===")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsJWT">IsJWT</span>
|
||||
|
||||
<p>Checks if a give string is is a valid JSON Web Token (JWT).</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsJWT(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/R6Op7heJbKI)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVzc2FnZSI6IlB1dGluIGlzIGFic29sdXRlIHNoaXQiLCJpYXQiOjE1MTYyMzkwMjJ9.wkLWA5GtCpWdxNOrRse8yHZgORDgf8TpJp73WUQb910")
|
||||
result2 := validator.IsJWT("abc")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsVisa">IsVisa</span>
|
||||
|
||||
<p>Checks if a give string is a valid visa card nubmer or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsVisa(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/SdS2keOyJsl)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsVisa("4111111111111111")
|
||||
result2 := validator.IsVisa("123")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsMasterCard">IsMasterCard</span>
|
||||
|
||||
<p>Checks if a give string is a valid mastercard nubmer or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsMasterCard(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CwWBFRrG27b)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsMasterCard("5425233430109903")
|
||||
result2 := validator.IsMasterCard("4111111111111111")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsAmericanExpress">IsAmericanExpress</span>
|
||||
|
||||
<p>Checks if a give string is a valid american express nubmer or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsAmericanExpress(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/HIDFpcOdpkd)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsAmericanExpress("342883359122187")
|
||||
result2 := validator.IsAmericanExpress("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsUnionPay">IsVisa</span>
|
||||
|
||||
<p>Checks if a give string is a valid union pay nubmer or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsUnionPay(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/CUHPEwEITDf)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsUnionPay("6221263430109903")
|
||||
result2 := validator.IsUnionPay("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
### <span id="IsChinaUnionPay">IsChinaUnionPay</span>
|
||||
|
||||
<p>Checks if a give string is a valid china union pay nubmer or not.</p>
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```go
|
||||
func IsChinaUnionPay(v string) bool
|
||||
```
|
||||
|
||||
<b>Example:<span style="float:right;display:inline-block">[Run](https://go.dev/play/p/yafpdxLiymu)</span></b>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result1 := validator.IsChinaUnionPay("6250941006528599")
|
||||
result2 := validator.IsChinaUnionPay("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1192,10 +1192,40 @@ func KeyBy[T any, U comparable](slice []T, iteratee func(item T) U) map[U]T {
|
||||
|
||||
// Join the slice item with specify separator.
|
||||
// Play: https://go.dev/play/p/huKzqwNDD7V
|
||||
func Join[T any](s []T, separator string) string {
|
||||
str := Map(s, func(_ int, item T) string {
|
||||
func Join[T any](slice []T, separator string) string {
|
||||
str := Map(slice, func(_ int, item T) string {
|
||||
return fmt.Sprint(item)
|
||||
})
|
||||
|
||||
return strings.Join(str, separator)
|
||||
}
|
||||
|
||||
// Partition all slice elements with the evaluation of the given predicate functions.
|
||||
// Play: https://go.dev/play/p/lkQ3Ri2NQhV
|
||||
func Partition[T any](slice []T, predicates ...func(item T) bool) [][]T {
|
||||
l := len(predicates)
|
||||
|
||||
result := make([][]T, l+1)
|
||||
|
||||
for _, item := range slice {
|
||||
processed := false
|
||||
|
||||
for i, f := range predicates {
|
||||
if f == nil {
|
||||
panic("predicate function must not be nill")
|
||||
}
|
||||
|
||||
if f(item) {
|
||||
result[i] = append(result[i], item)
|
||||
processed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !processed {
|
||||
result[l] = append(result[l], item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1046,3 +1046,20 @@ func ExampleJoin() {
|
||||
// 1,2,3,4,5
|
||||
// 1-2-3-4-5
|
||||
}
|
||||
|
||||
func ExamplePartition() {
|
||||
nums := []int{1, 2, 3, 4, 5}
|
||||
|
||||
result1 := Partition(nums)
|
||||
result2 := Partition(nums, func(n int) bool { return n%2 == 0 })
|
||||
result3 := Partition(nums, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 })
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
|
||||
// Output:
|
||||
// [[1 2 3 4 5]]
|
||||
// [[2 4] [1 3 5]]
|
||||
// [[1 2] [3 4] [5]]
|
||||
}
|
||||
|
||||
@@ -1175,3 +1175,13 @@ func TestJoin(t *testing.T) {
|
||||
assert.Equal("1,2,3,4,5", result1)
|
||||
assert.Equal("1-2-3-4-5", result2)
|
||||
}
|
||||
|
||||
func TestPartition(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := internal.NewAssert(t, "TestPartition")
|
||||
|
||||
assert.Equal([][]int{{1, 2, 3, 4, 5}}, Partition([]int{1, 2, 3, 4, 5}))
|
||||
assert.Equal([][]int{{2, 4}, {1, 3, 5}}, Partition([]int{1, 2, 3, 4, 5}, func(n int) bool { return n%2 == 0 }))
|
||||
assert.Equal([][]int{{1, 2}, {3, 4}, {5}}, Partition([]int{1, 2, 3, 4, 5}, func(n int) bool { return n == 1 || n == 2 }, func(n int) bool { return n == 2 || n == 3 || n == 4 }))
|
||||
}
|
||||
|
||||
@@ -16,19 +16,27 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
alphaMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]+$`)
|
||||
letterRegexMatcher *regexp.Regexp = regexp.MustCompile(`[a-zA-Z]`)
|
||||
numberRegexMatcher *regexp.Regexp = regexp.MustCompile(`\d`)
|
||||
intStrMatcher *regexp.Regexp = regexp.MustCompile(`^[\+-]?\d+$`)
|
||||
urlMatcher *regexp.Regexp = regexp.MustCompile(`^((ftp|http|https?):\/\/)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(([a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*)|((www\.)?))?(([a-z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-z\x{00a1}-\x{ffff}]{2,}))?))(:(\d{1,5}))?((\/|\?|#)[^\s]*)?$`)
|
||||
dnsMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$`)
|
||||
emailMatcher *regexp.Regexp = regexp.MustCompile(`\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`)
|
||||
chineseMobileMatcher *regexp.Regexp = regexp.MustCompile(`^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$`)
|
||||
chineseIdMatcher *regexp.Regexp = regexp.MustCompile(`^[1-9]\d{5}(18|19|20|21|22)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$`)
|
||||
chineseMatcher *regexp.Regexp = regexp.MustCompile("[\u4e00-\u9fa5]")
|
||||
chinesePhoneMatcher *regexp.Regexp = regexp.MustCompile(`\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}`)
|
||||
creditCardMatcher *regexp.Regexp = regexp.MustCompile(`^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11}|6[27][0-9]{14})$`)
|
||||
base64Matcher *regexp.Regexp = regexp.MustCompile(`^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$`)
|
||||
alphaMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]+$`)
|
||||
letterRegexMatcher *regexp.Regexp = regexp.MustCompile(`[a-zA-Z]`)
|
||||
numberRegexMatcher *regexp.Regexp = regexp.MustCompile(`\d`)
|
||||
intStrMatcher *regexp.Regexp = regexp.MustCompile(`^[\+-]?\d+$`)
|
||||
urlMatcher *regexp.Regexp = regexp.MustCompile(`^((ftp|http|https?):\/\/)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(([a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*)|((www\.)?))?(([a-z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-z\x{00a1}-\x{ffff}]{2,}))?))(:(\d{1,5}))?((\/|\?|#)[^\s]*)?$`)
|
||||
dnsMatcher *regexp.Regexp = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9\-]+[\.]?)*[a-zA-Z0-9]$`)
|
||||
emailMatcher *regexp.Regexp = regexp.MustCompile(`\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`)
|
||||
chineseMobileMatcher *regexp.Regexp = regexp.MustCompile(`^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$`)
|
||||
chineseIdMatcher *regexp.Regexp = regexp.MustCompile(`^[1-9]\d{5}(18|19|20|21|22)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$`)
|
||||
chineseMatcher *regexp.Regexp = regexp.MustCompile("[\u4e00-\u9fa5]")
|
||||
chinesePhoneMatcher *regexp.Regexp = regexp.MustCompile(`\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}`)
|
||||
creditCardMatcher *regexp.Regexp = regexp.MustCompile(`^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11}|6[27][0-9]{14})$`)
|
||||
base64Matcher *regexp.Regexp = regexp.MustCompile(`^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$`)
|
||||
base64URLMatcher *regexp.Regexp = regexp.MustCompile(`^([A-Za-z0-9_-]{4})*([A-Za-z0-9_-]{2}(==)?|[A-Za-z0-9_-]{3}=?)?$`)
|
||||
binMatcher *regexp.Regexp = regexp.MustCompile(`^(0b)?[01]+$`)
|
||||
hexMatcher *regexp.Regexp = regexp.MustCompile(`^(#|0x|0X)?[0-9a-fA-F]+$`)
|
||||
visaMatcher *regexp.Regexp = regexp.MustCompile(`^4[0-9]{12}(?:[0-9]{3})?$`)
|
||||
masterCardMatcher *regexp.Regexp = regexp.MustCompile(`^5[1-5][0-9]{14}$`)
|
||||
americanExpressMatcher *regexp.Regexp = regexp.MustCompile(`^3[47][0-9]{13}$`)
|
||||
unionPay *regexp.Regexp = regexp.MustCompile("^62[0-5]\\d{13,16}$")
|
||||
chinaUnionPay *regexp.Regexp = regexp.MustCompile(`^62[0-9]{14,17}$`)
|
||||
)
|
||||
|
||||
// IsAlpha checks if the string contains only letters (a-zA-Z).
|
||||
@@ -401,3 +409,68 @@ func IsInt(v any) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsBin check if a give string is a valid binary value or not.
|
||||
// Play: https://go.dev/play/p/ogPeg2XJH4P
|
||||
func IsBin(v string) bool {
|
||||
return binMatcher.MatchString(v)
|
||||
}
|
||||
|
||||
// IsHex check if a give string is a valid hexadecimal value or not.
|
||||
// Play: https://go.dev/play/p/M2qpHbEwmm7
|
||||
func IsHex(v string) bool {
|
||||
return hexMatcher.MatchString(v)
|
||||
}
|
||||
|
||||
// IsBase64URL check if a give string is a valid URL-safe Base64 encoded string.
|
||||
// Play: https://go.dev/play/p/vhl4mr8GZ6S
|
||||
func IsBase64URL(v string) bool {
|
||||
return base64URLMatcher.MatchString(v)
|
||||
}
|
||||
|
||||
// IsJWT check if a give string is a valid JSON Web Token (JWT).
|
||||
// Play: https://go.dev/play/p/R6Op7heJbKI
|
||||
func IsJWT(v string) bool {
|
||||
strings := strings.Split(v, ".")
|
||||
if len(strings) != 3 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, s := range strings {
|
||||
if !IsBase64URL(s) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// IsVisa check if a give string is a valid visa card nubmer or not.
|
||||
// Play: https://go.dev/play/p/SdS2keOyJsl
|
||||
func IsVisa(v string) bool {
|
||||
return visaMatcher.MatchString(v)
|
||||
}
|
||||
|
||||
// IsMasterCard check if a give string is a valid master card nubmer or not.
|
||||
// Play: https://go.dev/play/p/CwWBFRrG27b
|
||||
func IsMasterCard(v string) bool {
|
||||
return masterCardMatcher.MatchString(v)
|
||||
}
|
||||
|
||||
// IsAmericanExpress check if a give string is a valid american expression card nubmer or not.
|
||||
// Play: https://go.dev/play/p/HIDFpcOdpkd
|
||||
func IsAmericanExpress(v string) bool {
|
||||
return americanExpressMatcher.MatchString(v)
|
||||
}
|
||||
|
||||
// IsUnionPay check if a give string is a valid union pay nubmer or not.
|
||||
// Play: https://go.dev/play/p/CUHPEwEITDf
|
||||
func IsUnionPay(v string) bool {
|
||||
return unionPay.MatchString(v)
|
||||
}
|
||||
|
||||
// IsChinaUnionPay check if a give string is a valid china union pay nubmer or not.
|
||||
// Play: https://go.dev/play/p/yafpdxLiymu
|
||||
func IsChinaUnionPay(v string) bool {
|
||||
return chinaUnionPay.MatchString(v)
|
||||
}
|
||||
|
||||
@@ -521,3 +521,129 @@ func ExampleIsNumber() {
|
||||
// true
|
||||
// true
|
||||
}
|
||||
|
||||
func ExampleIsBin() {
|
||||
result1 := IsBin("0101")
|
||||
result2 := IsBin("0b1101")
|
||||
result3 := IsBin("b1101")
|
||||
result4 := IsBin("1201")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsHex() {
|
||||
result1 := IsHex("0xabcde")
|
||||
result2 := IsHex("0XABCDE")
|
||||
result3 := IsHex("cdfeg")
|
||||
result4 := IsHex("0xcdfeg")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsBase64URL() {
|
||||
result1 := IsBase64URL("SAGsbG8sIHdvcmxkIQ")
|
||||
result2 := IsBase64URL("SAGsbG8sIHdvcmxkIQ==")
|
||||
result3 := IsBase64URL("SAGsbG8sIHdvcmxkIQ=")
|
||||
result4 := IsBase64URL("SAGsbG8sIHdvcmxkIQ===")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsJWT() {
|
||||
result1 := IsJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVzc2FnZSI6IlB1dGluIGlzIGFic29sdXRlIHNoaXQiLCJpYXQiOjE1MTYyMzkwMjJ9.wkLWA5GtCpWdxNOrRse8yHZgORDgf8TpJp73WUQb910")
|
||||
result2 := IsJWT("abc")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsVisa() {
|
||||
result1 := IsVisa("4111111111111111")
|
||||
result2 := IsVisa("123")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsMasterCard() {
|
||||
result1 := IsMasterCard("5425233430109903")
|
||||
result2 := IsMasterCard("4111111111111111")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsAmericanExpress() {
|
||||
result1 := IsAmericanExpress("342883359122187")
|
||||
result2 := IsAmericanExpress("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsUnionPay() {
|
||||
result1 := IsUnionPay("6221263430109903")
|
||||
result2 := IsUnionPay("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsChinaUnionPay() {
|
||||
result1 := IsChinaUnionPay("6250941006528599")
|
||||
result2 := IsChinaUnionPay("3782822463100007")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
}
|
||||
|
||||
@@ -231,7 +231,12 @@ func TestIsIpV4(t *testing.T) {
|
||||
assert := internal.NewAssert(t, "TestIsIpV4")
|
||||
|
||||
assert.Equal(true, IsIpV4("127.0.0.1"))
|
||||
|
||||
assert.Equal(false, IsIpV4("::0:0:0:0:0:0:1"))
|
||||
assert.Equal(false, IsIpV4("127.0.0.1.1"))
|
||||
assert.Equal(false, IsIpV4("256.0.0.1"))
|
||||
assert.Equal(false, IsIpV4("127.0.0.a"))
|
||||
assert.Equal(false, IsIpV4(""))
|
||||
}
|
||||
|
||||
func TestIsIpV6(t *testing.T) {
|
||||
@@ -239,8 +244,14 @@ func TestIsIpV6(t *testing.T) {
|
||||
|
||||
assert := internal.NewAssert(t, "TestIsIpV6")
|
||||
|
||||
assert.Equal(false, IsIpV6("127.0.0.1"))
|
||||
assert.Equal(true, IsIpV6("::0:0:0:0:0:0:1"))
|
||||
assert.Equal(true, IsIpV6("::1"))
|
||||
assert.Equal(true, IsIpV6("::"))
|
||||
|
||||
assert.Equal(false, IsIpV6("127.0.0.1"))
|
||||
assert.Equal(false, IsIpV6("2001:db8::8a2e:37023:7334"))
|
||||
assert.Equal(false, IsIpV6("2001::25de::cade"))
|
||||
assert.Equal(false, IsIpV6(""))
|
||||
}
|
||||
|
||||
func TestIsUrl(t *testing.T) {
|
||||
@@ -536,3 +547,90 @@ func TestIsPrintable(t *testing.T) {
|
||||
assert.Equal(true, IsPrintable("😄"))
|
||||
assert.Equal(false, IsPrintable("\u0000"))
|
||||
}
|
||||
|
||||
func TestIsBin(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsBin")
|
||||
|
||||
assert.Equal(true, IsBin("0101"))
|
||||
assert.Equal(true, IsBin("0b1101"))
|
||||
|
||||
assert.Equal(false, IsBin("b1101"))
|
||||
assert.Equal(false, IsBin("1201"))
|
||||
assert.Equal(false, IsBin(""))
|
||||
}
|
||||
|
||||
func TestIsHex(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsHex")
|
||||
|
||||
assert.Equal(true, IsHex("ABCDE"))
|
||||
assert.Equal(true, IsHex("abcde"))
|
||||
assert.Equal(true, IsHex("0xabcde"))
|
||||
assert.Equal(true, IsHex("0Xabcde"))
|
||||
assert.Equal(true, IsHex("#abcde"))
|
||||
|
||||
assert.Equal(false, IsHex("cdfeg"))
|
||||
assert.Equal(false, IsHex("0xcdfeg"))
|
||||
assert.Equal(false, IsHex(""))
|
||||
}
|
||||
|
||||
func TestIsBase64URL(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsBase64URL")
|
||||
|
||||
assert.Equal(true, IsBase64URL("SAGsbG8sIHdvcmxkIQ"))
|
||||
assert.Equal(true, IsBase64URL("SAGsbG8sIHdvcmxkIQ=="))
|
||||
|
||||
assert.Equal(false, IsBase64URL("SAGsbG8sIHdvcmxkIQ="))
|
||||
assert.Equal(false, IsBase64URL("SAGsbG8sIHdvcmxkIQ==="))
|
||||
// assert.Equal(false, IsBase64URL(""))
|
||||
}
|
||||
|
||||
func TestIsJWT(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsJWT")
|
||||
|
||||
assert.Equal(true, IsJWT("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibWVzc2FnZSI6IlB1dGluIGlzIGFic29sdXRlIHNoaXQiLCJpYXQiOjE1MTYyMzkwMjJ9.wkLWA5GtCpWdxNOrRse8yHZgORDgf8TpJp73WUQb910"))
|
||||
assert.Equal(false, IsJWT("abc"))
|
||||
}
|
||||
|
||||
func TestIsVisa(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsVisa")
|
||||
|
||||
assert.Equal(true, IsVisa("4111111111111111"))
|
||||
assert.Equal(false, IsVisa("123"))
|
||||
}
|
||||
|
||||
func TestIsMasterCard(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsMasterCard")
|
||||
|
||||
assert.Equal(true, IsMasterCard("5425233430109903"))
|
||||
assert.Equal(false, IsMasterCard("4111111111111111"))
|
||||
}
|
||||
|
||||
func TestIsAmericanExpress(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsAmericanExpress")
|
||||
|
||||
assert.Equal(true, IsAmericanExpress("342883359122187"))
|
||||
assert.Equal(false, IsAmericanExpress("3782822463100007"))
|
||||
}
|
||||
|
||||
func TestIsUnionPay(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsUnionPay")
|
||||
|
||||
assert.Equal(true, IsUnionPay("6221263430109903"))
|
||||
assert.Equal(false, IsUnionPay("3782822463100007"))
|
||||
}
|
||||
|
||||
func TestIsChinaUnionPay(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := internal.NewAssert(t, "TestIsChinaUnionPay")
|
||||
|
||||
assert.Equal(true, IsChinaUnionPay("6250941006528599"))
|
||||
assert.Equal(false, IsChinaUnionPay("3782822463100007"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user