@ersbeth/xtypebox
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

xTypeBox

Additional utilities for TypeBox.

Installation

npm install @ersbeth/xtypebox

Usage

String formats

xTypeBox provides additional string formats for validation. First you must configure them:

import { IsDate, IsTime, IsDateTime, IsEmail, IsUrl, IsImageDataUrl, IsUuid, IsIPv4, IsIPv6, } from "@ersbeth/xtypebox";

FormatRegistry.Set('date', IsDate)
FormatRegistry.Set('time', IsTime)
FormatRegistry.Set('date-time', IsDateTime)

FormatRegistry.Set('email', IsEmail)
FormatRegistry.Set('url', IsUrl)
FormatRegistry.Set('url-image', IsImageDataUrl)

FormatRegistry.Set('uuid', IsUuid)

FormatRegistry.Set('ipv4', IsIPv4)
FormatRegistry.Set('ipv6', IsIPv6)

Then you may use them in any typebox type:

const Schema = Type.Object({
    url: Type.String({ format: "url" }),
    imageDataUrl: Type.String({ format: "url-image" }),
    email: Type.String({ format: "email" })
})

Readme

Keywords

Package Sidebar

Install

npm i @ersbeth/xtypebox

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

27.9 kB

Total Files

26

Last publish

Collaborators

  • erousset