Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The modular and type safe schema library for validating structural data 🤖

License

NotificationsYou must be signed in to change notification settings

open-circle/valibot

Valibot Logo

Valibot

License: MITCINPM versionDownloadsJSR versionDiscord

Hello, I am Valibot and I would like to help you validate data easily using a schema. No matter if it is incoming data on a server, a form or even configuration files. I have no dependencies and can run in any JavaScript environment.

I highly recommend you read theannouncement post, and if you are a nerd like me, thebachelor's thesis I am based on.

Highlights

  • Fully type safe with static type inference
  • Small bundle size starting at less than 700 bytes
  • Validate everything from strings to complex objects
  • Open source and fully tested with 100 % coverage
  • Many transformation and validation actions included
  • Well structured source code without dependencies
  • Minimal, readable and well thought out API

Example

First you create a schema that describes a structured data set. A schema can be compared to a type definition in TypeScript. The big difference is that TypeScript types are "not executed" and are more or less a DX feature. A schema on the other hand, apart from the inferred type definition, can also be executed at runtime to guarantee the type safety of unknown data.

import*asvfrom'valibot';// 1.31 kB// Create login schema with email and passwordconstLoginSchema=v.object({email:v.pipe(v.string(),v.email()),password:v.pipe(v.string(),v.minLength(8)),});// Infer output TypeScript type of login schema as// { email: string; password: string }typeLoginData=v.InferOutput<typeofLoginSchema>;// Throws error for email and passwordconstoutput1=v.parse(LoginSchema,{email:'',password:''});// Returns data as { email: string; password: string }constoutput2=v.parse(LoginSchema,{email:'jane@example.com',password:'12345678',});

Apart fromparse I also offer a non-exception-based API withsafeParse and a type guard function withis. You can read more about ithere.

Comparison

Instead of relying on a few large functions with many methods, my API design and source code is based on many small and independent functions, each with just a single task. This modular design has several advantages.

For example, this allows a bundler to use the import statements to remove code that is not needed. This way, only the code that is actually used gets into your production build. This can reduce the bundle size by up to 95 % compared toZod.

In addition, it allows you to easily extend my functionality with external code and makes my source code more robust and secure because the functionality of the individual functions can be tested much more easily through unit tests.

Partners

Thanks to our partners who support my development!Join them and contribute to the sustainability of open source software!

Partners of Valibot

Credits

My friendFabian created me as part of hisbachelor thesis atStuttgart Media University, supervised by Walter Kriha,Miško Hevery andRyan Carniato. My role models also includeColin McDonnell, who had a big influence on my API design withZod.

Feedback

Find a bug or have an idea how to improve my code? Please fill out anissue. Together we can make the library even better!

License

I am completely free and licensed under theMIT license. But if you like, you can feed me with a star onGitHub.

About

The modular and type safe schema library for validating structural data 🤖

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  
  •  
  •  

Contributors185

Languages


[8]ページ先頭

©2009-2026 Movatter.jp