1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 06:32:28 +08:00

feat: add IsBin, IsHex, IsBase64URL, IsJWT

This commit is contained in:
dudaodong
2023-09-06 17:42:31 +08:00
parent 20786c360b
commit 71c7733eb0
3 changed files with 152 additions and 0 deletions

View File

@@ -521,3 +521,69 @@ 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
}