Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Reviewed-on: https://git.jvalver.de/Thilawyn/schemable-class/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
18
src/jsonifiable/schema/bigint.ts
Normal file
18
src/jsonifiable/schema/bigint.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export const jsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
|
||||
schema.transform(v => v.toString())
|
||||
|
||||
export const dejsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
|
||||
z
|
||||
.string()
|
||||
.transform(v => {
|
||||
try {
|
||||
return BigInt(v)
|
||||
}
|
||||
catch (e) {
|
||||
return v
|
||||
}
|
||||
})
|
||||
.pipe(schema)
|
||||
Reference in New Issue
Block a user