Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ark/type/__tests__/integration/allConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ configure({
"string.hex": {
description: "configured"
},
"string.base58": {
description: "configured"
},
"string.base64.url": {
description: "configured"
},
Expand Down
13 changes: 13 additions & 0 deletions ark/type/__tests__/keywords/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ contextualize(() => {
)
})

it("base58", () => {
const Base58 = type("string.base58")
attest(Base58("5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ")).snap(
"5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"
)
attest(Base58("abc123")).snap("abc123")
attest(Base58("0").toString()).snap('must be base58-encoded (was "0")')
attest(Base58("O").toString()).snap('must be base58-encoded (was "O")')
attest(Base58("I").toString()).snap('must be base58-encoded (was "I")')
attest(Base58("l").toString()).snap('must be base58-encoded (was "l")')
attest(Base58("").toString()).snap('must be base58-encoded (was "")')
})

it("base64", () => {
const B64 = type("string.base64")
attest(B64("fn5+")).snap("fn5+")
Expand Down
4 changes: 4 additions & 0 deletions ark/type/keywords/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export declare namespace stringInteger {

const hex = regexStringNode(/^[\dA-Fa-f]+$/, "hex characters only")

const base58 = regexStringNode(/^[1-9A-HJ-NP-Za-km-z]+$/, "base58-encoded")

const base64 = Scope.module(
{
root: regexStringNode(
Expand Down Expand Up @@ -911,6 +913,7 @@ export const string = Scope.module(
"only letters and digits 0-9"
),
hex,
base58,
base64,
capitalize,
creditCard,
Expand Down Expand Up @@ -945,6 +948,7 @@ export declare namespace string {
alpha: string
alphanumeric: string
hex: string
base58: string
base64: base64.submodule
capitalize: capitalize.submodule
creditCard: string
Expand Down
Loading