fabian-hiller/valibot
Fork: 202 Star: 6295 (更新于 2024-11-19 14:50:17)
license: MIT
Language: TypeScript .
The modular and type safe schema library for validating structural data 🤖
最后发布版本: v1.0.0-beta.0-i18n ( 2024-10-02 12:06:55)
Valibot
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 the announcement post, and if you are a nerd like me, the bachelor's thesis I am based on.
Highlights
- Fully type safe with static type inference
- Small bundle size starting at less than 600 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 type safety of unknown data.
import * as v from 'valibot'; // 1.24 kB
// Create login schema with email and password
const LoginSchema = v.object({
email: v.pipe(v.string(), v.email()),
password: v.pipe(v.string(), v.minLength(8)),
});
// Infer output TypeScript type of login schema
type LoginData = v.InferOutput<typeof LoginSchema>; // { email: string; password: string }
// Throws error for `email` and `password`
v.parse(LoginSchema, { email: '', password: '' });
// Returns data as { email: string; password: string }
v.parse(LoginSchema, { email: 'jane@example.com', password: '12345678' });
Apart from parse
I also offer a non-exception-based API with safeParse
and a type guard function with is
. You can read more about it here.
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 to Zod.
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.
Credits
My friend Fabian created me as part of his bachelor thesis at Stuttgart Media University, supervised by Walter Kriha, Miško Hevery and Ryan Carniato. My role models also include Colin McDonnell, who had a big influence on my API design with Zod.
Feedback
Find a bug or have an idea how to improve my code? Please fill out an issue. Together we can make the library even better!
License
I am completely free and licensed under the MIT license. But if you like, you can feed me with a star on GitHub.
最近版本更新:(数据更新于 2024-10-04 12:19:55)
2024-10-02 12:06:55 v1.0.0-beta.0-i18n
2024-10-01 11:30:03 1.0.0-beta.0-to-json-schema
2024-10-01 11:16:41 v1.0.0-beta.0
2024-09-30 22:50:30 v0.2.1-to-json-schema
2024-09-21 00:01:34 v0.42.1
2024-09-15 12:22:23 v0.2.0-to-json-schema
2024-09-15 12:15:33 v0.42.0
2024-09-15 07:15:14 v0.1.1-to-json-schema
2024-09-14 01:41:27 v0.1.0-to-json-schema
2024-09-02 02:17:15 v0.41.0
主题(topics):
bundle-size, hacktoberfest, modular, parsing, runtime, schema, type-safe, typescript, validation
fabian-hiller/valibot同语言 TypeScript最近更新仓库
2024-11-21 16:58:07 labring/FastGPT
2024-11-21 16:14:54 RSSNext/Follow
2024-11-21 14:41:29 continuedev/continue
2024-11-21 00:40:00 immich-app/immich
2024-11-20 19:46:23 CopilotKit/CopilotKit
2024-11-20 18:49:53 awslabs/multi-agent-orchestrator