MyGit
🚩收到GitHub仓库的更新通知

fabian-hiller/valibot

Fork: 132 Star: 4854 (更新于 2024-02-23 19:56:49)

license: MIT

Language: TypeScript .

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

最后发布版本: v0.29.0 ( 2024-02-20 12:33:23)

官方网址 GitHub网址

✨免费申请网站SSL证书,支持多域名和泛域名,点击查看

Valibot Logo

Valibot

License: MIT CI NPM version Downloads

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 helpers 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 { email, minLength, object, type Output, parse, string } from 'valibot'; // 1.54 kB

// Create login schema with email and password
const LoginSchema = object({
  email: string([email()]),
  password: string([minLength(8)]),
});

// Infer output TypeScript type of login schema
type LoginData = Output<typeof LoginSchema>; // { email: string; password: string }

// Throws error for `email` and `password`
parse(LoginSchema, { email: '', password: '' });

// Returns data as { email: string; password: string }
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-02-23 19:56:32)

2024-02-20 12:33:23 v0.29.0

2024-02-07 01:50:34 v0.28.1

2024-02-06 09:45:13 v0.28.0

2024-01-29 02:12:01 v0.27.1

2024-01-25 00:22:21 v0.27.0

2024-01-17 10:42:20 v0.26.0

2023-12-27 11:37:30 v0.25.0

2023-12-12 00:37:29 v0.24.1

2023-12-11 12:14:05 v0.24.0

2023-12-09 01:32:49 v0.23.0

主题(topics):

bundle-size, modular, parsing, runtime, schema, type-safe, typescript, validation

fabian-hiller/valibot同语言 TypeScript最近更新仓库

2024-03-05 01:16:09 vercel/ai

2024-03-04 16:52:27 illacloud/illa-builder

2024-03-03 23:42:46 siyuan-note/siyuan

2024-03-03 22:10:13 zanllp/sd-webui-infinite-image-browsing

2024-03-03 15:22:18 digimezzo/dopamine

2024-03-03 12:36:04 cooderl/wewe-rss