Skip to content

Commit

Permalink
Add typebox_utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Oct 5, 2023
1 parent 4562bb7 commit 7565418
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/typebox_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TSchema, Type } from "./deps/typebox.ts";

export const NonEmptyString = (props?: Parameters<typeof Type.String>[0]) => Type.String({ minLength: 1, ...props });

export const PosInt = (props?: Parameters<typeof Type.Integer>[0]) =>
Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, ...props });

export const NonNegInt = (props?: Parameters<typeof Type.Integer>[0]) =>
Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, ...props });

export const Maybe = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Undefined()]);

export const Nullable = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Null()]);

0 comments on commit 7565418

Please sign in to comment.