elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.23k stars 198 forks source link

Add additional string formats directly from ajv-formats #584

Closed FDiskas closed 3 months ago

FDiskas commented 3 months ago

Elysiajs uses sinclairzx81/typebox and it recommends to use ajv-formats more info

Because elysiajs is implemented his way to validate certain formats I just reused regexp strings directly from source https://github.com/ajv-validator/ajv-formats/blob/1fb3fa7d967f919ff924bb34aef73a2f39ab0de3/src/formats.ts#L45

This allows us to use (not all) formats

const app = new Elysia().get(
  '/',
  ({ query }) => query,
  {
    query: t.Object({
      host: t.String({
        format: 'hostname'
      })
    })
  }
)

closes #578