Skip to content

Commit 0d77447

Browse files
authored
add valibot to comparison
2 parents a0e67fd + 0a92136 commit 0d77447

18 files changed

+378
-98
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enable-pre-post-scripts=true

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.13.1

.repo-checker.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"license": "MIT"
3+
}

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"editor.quickSuggestions": {
3-
"strings": "on"
3+
"strings": "on"
44
},
55
// prioritize ArkType's "type" for autoimports
66
"typescript.preferences.autoImportSpecifierExcludeRegexes": [
7-
"^(node:)?os$"
7+
"^(node:)?os$"
8+
],
9+
"cSpell.words": [
10+
"arktype",
11+
"valibot"
812
],
913
}

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Jordan Boyer
4+
Copyright (c) 2025 Romain Racamier-Lafon
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,92 @@
1-
# validation-lib-comparaison
1+
# Validation lib comparaison
22

3-
To install dependencies:
3+
[![Project license](https://img.shields.io/github/license/Shuunen/validation-lib-comparison.svg?color=informational)](https://github.com/Shuunen/validation-lib-comparison/blob/master/LICENSE)
4+
5+
## The goal of this project
6+
7+
The goal is to compare different libraries and approaches to validate data in a TypeScript ecosystem.
8+
9+
It's interesting to see how each library is designed, how it's used, and how it performs.
10+
11+
Ideally you can use this comparison to choose the library that fits your needs the best.
12+
13+
## Run tests and benchmarks
14+
15+
Make sure you have [Bun](https://bun.sh) v1.1.x then :
416

517
```bash
18+
# install the dependencies
619
bun install
20+
# run each file once just to verify that everything is working as expected
21+
bun bench --runs 1
22+
# run the benchmarks
23+
bun bench --runs 50
724
```
825

9-
To run:
26+
At the time of writing, Node 22 is around 2 times slower than Bun v1 ^^'
1027

11-
```bash
12-
bun run index.ts
13-
```
28+
## The comparison results
29+
30+
Here are the library used in this comparison :
31+
32+
- [arktype](https://github.com/arktypeio/arktype) v2.0.4 from David Blass
33+
- [valibot](https://github.com/fabian-hiller/valibot) v1.0.0-rc.1 from Fabian Hiller
34+
- [zod](https://github.com/colinhacks/zod) v3.24.2 from Colin McDonnell
35+
36+
| Date | Score | Library | Deps | Size | Light | Input | Throw | Safe | Execution | Fast |
37+
| ---------- | :---: | :-----: | :---: | :----: | :---: | :---: | :---: | :---: | :-------: | :---: |
38+
| 2025-02-21 | 2 | arktype | 2 | 133 KB | 0 | **1** | 0 | **1** | 155 ms | 0 |
39+
| 2025-02-21 | 6 | valibot | **0** | 4 KB | **2** | **1** | **1** | **1** | 74 ms | **1** |
40+
| 2025-02-21 | 4 | zod | **0** | 62 KB | 0 | **1** | **1** | **1** | 75 ms | **1** |
41+
42+
Legend :
43+
44+
- Deps : the number of dependencies of the library
45+
- Size : the minified build size in bytes of the related file in `src`, run `bun run build` to see by yourself
46+
- Light : 1 point if the build is less than 10 KB, 1 bonus point if it's less than 5 KB
47+
- Input : 1 point if the library can see that `age` is optional in the input but not optional in `type User` the output type
48+
- Throw : 1 point if the library have a parse or throw method, useful when we don't want to handle the error cases
49+
- Safe : 1 point if the library have a safe parse method that will not throw and usually return a `Result` type
50+
- Execution : average time in milliseconds to execute the test file with bun, check the `bun run bench` command output
51+
- Fast : 1 point if the library execution time is less than 100 ms
52+
53+
## My favorite pick
54+
55+
Valibot is my favorite pick because it's fast as Zod but has a lighter impact on the bundle size.
56+
57+
## Todo
58+
59+
- [ ] vanilla version ?
60+
- [ ] check error messages
61+
- [ ] check custom error messages
62+
- [ ] check custom validation rules
63+
64+
## How to contribute
65+
66+
There are many ways to contribute to this project :
67+
68+
- Add a new library to the comparison
69+
- Improve the comparison table, criteria, or scoring
70+
- Improve the samples in `src`
71+
- Find a way to enhance library isolation to have more meaningful benchmarks
72+
- Whatever you think that could be useful, check the above todo list for inspiration
73+
74+
Just open an issue or a PR, I'll be happy to discuss it with you <3
75+
76+
## Thanks
77+
78+
- [Arktype](https://github.com/arktypeio/arktype) : for making this comparison possible
79+
- [Bun](https://bun.sh) : for their great tool to do almost everything ^^
80+
- [Github](https://github.com) : for all their great work year after year, pushing OSS forward
81+
- [Repo-checker](https://github.com/Shuunen/repo-checker) : eslint cover /src code and this tool the rest ^^
82+
- [Shields.io](https://shields.io) : for the nice badges on top of this readme
83+
- [Valibot](https://github.com/fabian-hiller/valibot) : for making this comparison possible
84+
- [Zod](https://github.com/colinhacks/zod) : for making this comparison possible
85+
86+
## Stargazers over time
87+
88+
[![Stargazers over time](https://starchart.cc/Shuunen/validation-lib-comparison.svg?variant=adaptive)](https://starchart.cc/Shuunen/validation-lib-comparison)
89+
90+
## Page views
1491

15-
This project was created using `bun init` in bun v1.1.8. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
92+
[![Free Website Counter](https://www.websitecounterfree.com/c.php?d=9&id=65903&s=12)](https://www.websitecounterfree.com)

arktype.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

bun.lock

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,63 @@
11
{
2-
"lockfileVersion": 1,
2+
"lockfileVersion": 0,
33
"workspaces": {
44
"": {
5-
"name": "validation-lib-comparaison",
65
"dependencies": {
7-
"arktype": "^2.0.0",
8-
"zod": "^3.24.1",
6+
"arktype": "^2.0",
7+
"valibot": "latest",
8+
"zod": "^3.24",
99
},
1010
"devDependencies": {
11+
"@tsconfig/strictest": "^2.0",
1112
"@types/bun": "latest",
12-
},
13-
"peerDependencies": {
14-
"typescript": "^5.0.0",
13+
"repo-check": "^1.40",
14+
"typescript": "^5.7",
1515
},
1616
},
1717
},
1818
"packages": {
19-
"@ark/schema": ["@ark/[email protected]", "", { "dependencies": { "@ark/util": "0.36.0" } }, "sha512-1zL+9AjNk6fNcCp5krt3HxM80kFr+MskqH2Gbz60GzXsjsAVZ38xM5WFVZMEPL8VbmTqDvBiwPm7HvK972lADg=="],
19+
"@ark/schema": ["@ark/[email protected]", "", { "dependencies": { "@ark/util": "0.39.0" } }, "sha512-LQbQUb3Sj461LgklXObAyUJNtsUUCBxZlO2HqRLYvRSqpStm0xTMrXn51DwBNNxeSULvKVpXFwoxiSec9kwKww=="],
20+
21+
"@ark/util": ["@ark/[email protected]", "", {}, "sha512-90APHVklk8BP4kku7hIh1BgrhuyKYqoZ4O7EybtFRo7cDl9mIyc/QUbGvYDg//73s0J2H0I/gW9pzroA1R4IBQ=="],
2022

21-
"@ark/util": ["@ark/[email protected]", "", {}, "sha512-3tn3udpNeoLdmU1kvJYjDnhXereB2PYHED2c2j8Q7OsIRMx+AlOCXWjsI4qjAarjjbfCsKtsdMlE2QnLrcVCuA=="],
23+
"@tsconfig/strictest": ["@tsconfig/[email protected]", "", {}, "sha512-ec4tjL2Rr0pkZ5hww65c+EEPYwxOi4Ryv+0MtjeaSQRJyq322Q27eOQiFbuNgw2hpL4hB1/W/HBGk3VKS43osg=="],
2224

23-
"@types/bun": ["@types/[email protected].0", "", { "dependencies": { "bun-types": "1.2.0" } }, "sha512-5N1JqdahfpBlAv4wy6svEYcd/YfO2GNrbL95JOmFx8nkE6dbK4R0oSE5SpBA4vBRqgrOUAXF8Dpiz+gi7r80SA=="],
25+
"@types/bun": ["@types/[email protected].2", "", { "dependencies": { "bun-types": "1.2.2" } }, "sha512-tr74gdku+AEDN5ergNiBnplr7hpDp3V1h7fqI2GcR/rsUaM39jpSeKH0TFibRvU0KwniRx5POgaYnaXbk0hU+w=="],
2426

25-
"@types/node": ["@types/node@22.10.10", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-X47y/mPNzxviAGY5TcYPtYL8JsY3kAq2n8fMmKoRCxq/c4v4pyGNCzM2R6+M5/umG4ZfHuT+sgqDYqWc9rJ6ww=="],
27+
"@types/node": ["@types/node@22.13.4", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg=="],
2628

2729
"@types/ws": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
2830

29-
"arktype": ["[email protected]", "", { "dependencies": { "@ark/schema": "0.36.0", "@ark/util": "0.36.0" } }, "sha512-IfczIefYOd2Omac9J1MH8YKmhGe4pQor1rg3w9mc6m8DA9fSnBRI7GF0XP8GQiHH5Khlj6MS6J1ZPbt68HDbrQ=="],
31+
"arg": ["[email protected]", "", {}, "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg=="],
32+
33+
"arktype": ["[email protected]", "", { "dependencies": { "@ark/schema": "0.39.0", "@ark/util": "0.39.0" } }, "sha512-S68rWVDnJauwH7/QCm8zCUM3aTe9Xk6oRihdcc3FSUAtxCo/q1Fwq46JhcwB5Ufv1YStwdQRz+00Y/URlvbhAQ=="],
34+
35+
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-RCbMH5elr9gjgDGDhkTTugA21XtJAy/9jkKe/G3WR2q17VPGhcquf9Sir6uay9iW+7P/BV0CAHA1XlHXMAVKHg=="],
36+
37+
"detect-indent": ["[email protected]", "", {}, "sha512-rlpvsxUtM0PQvy9iZe640/IWwWYyBsTApREbA1pHOpmOUIl9MkP/U4z7vTtg4Oaojvqhxt7sdufnT0EzGaR31g=="],
38+
39+
"detect-newline": ["[email protected]", "", {}, "sha512-CwffZFvlJffUg9zZA0uqrjQayUTC8ob94pnr5sFwaVv3IOmkfUHcWH+jXaQK3askE51Cqe8/9Ql/0uXNwqZ8Zg=="],
40+
41+
"globalyzer": ["[email protected]", "", {}, "sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q=="],
3042

31-
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-KEaJxyZfbV/c4eyG0vyehDpYmBGreNiQbZIqvVHJwZ4BmeuWlNZ7EAzMN2Zcd7ailmS/tGVW0BgYbGf+lGEpWw=="],
43+
"globrex": ["[email protected]", "", {}, "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg=="],
44+
45+
"minimist": ["[email protected]", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="],
46+
47+
"repo-check": ["[email protected]", "", { "dependencies": { "arg": "5.0", "shuutils": "10.1", "sort-json": "2.0" }, "bin": { "repo-check": "dist/repo-check.min.cjs" } }, "sha512-EO5AKEYlUU8cRDq/9PVEkTsQ19371lCdw38KTHVWH48Nxq7kS6uJXYEHBii/AQ0kXRVxJP57uMi84lGH5zNRZQ=="],
48+
49+
"shuutils": ["[email protected]", "", { "dependencies": { "tiny-glob": "0.2" }, "bin": { "unique-mark": "dist/unique-mark.cjs" } }, "sha512-Q+8PaUIik4W3bEE2xtDMZvYC7y4B8mnh3x7cneXPJmry0esVRir+hSZHh5Kjh6rtV0pYj+eKtAXBxJ8LDqPZhA=="],
50+
51+
"sort-json": ["[email protected]", "", { "dependencies": { "detect-indent": "^5.0.0", "detect-newline": "^2.1.0", "minimist": "^1.2.0" }, "bin": { "sort-json": "app/cmd.js" } }, "sha512-s8cs2bcsQCzo/P2T/uoU6Js4dS/jnX8+4xunziNoq9qmSpZNCrRIAIvp4avsz0ST18HycV4z/7myJ7jsHWB2XQ=="],
52+
53+
"tiny-glob": ["[email protected]", "", { "dependencies": { "globalyzer": "0.1.0", "globrex": "^0.1.2" } }, "sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg=="],
3254

3355
"typescript": ["[email protected]", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw=="],
3456

3557
"undici-types": ["[email protected]", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
3658

37-
"zod": ["[email protected]", "", {}, "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A=="],
59+
"valibot": ["[email protected]", "", { "peerDependencies": { "typescript": ">=5" }, "optionalPeers": ["typescript"] }, "sha512-bTHNpeeQ403xS7qGHF/tw3EC/zkZOU5VdkfIsmRDu1Sp+BJNTNCm6m5HlwOgyW/03lofP+uQiq3R+Poo9wiCEg=="],
60+
61+
"zod": ["[email protected]", "", {}, "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ=="],
3862
}
3963
}

package.json

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,55 @@
11
{
2-
"name": "validation-lib-comparaison",
3-
"module": "index.ts",
4-
"type": "module",
2+
"$schema": "https://json.schemastore.org/package",
3+
"author": "Jordan Boyer",
4+
"bugs": "https://github.com/Shuunen/validation-lib-comparison/issues",
5+
"contributors": [
6+
{
7+
"name": "Jordan Boyer"
8+
},
9+
{
10+
"email": "[email protected]",
11+
"name": "Romain Racamier-Lafon"
12+
}
13+
],
14+
"dependencies": {
15+
"arktype": "^2.0",
16+
"valibot": "latest",
17+
"zod": "^3.24"
18+
},
19+
"description": "Comparison of different TypeScript validation libraries",
520
"devDependencies": {
6-
"@types/bun": "latest"
21+
"@tsconfig/strictest": "^2.0",
22+
"@types/bun": "latest",
23+
"repo-check": "^1.40",
24+
"typescript": "^5.7"
725
},
8-
"peerDependencies": {
9-
"typescript": "^5.0.0"
26+
"files": [
27+
"dist"
28+
],
29+
"homepage": "https://github.com/Shuunen/validation-lib-comparison#readme",
30+
"keywords": [
31+
"shuunen",
32+
"typescript",
33+
"validation",
34+
"comparison"
35+
],
36+
"license": "MIT",
37+
"module": "index.ts",
38+
"name": "validation-lib-comparaison",
39+
"private": true,
40+
"repository": {
41+
"type": "git",
42+
"url": "git+https://github.com/Shuunen/validation-lib-comparison.git"
1043
},
11-
"dependencies": {
12-
"arktype": "^2.0.0",
13-
"zod": "^3.24.1"
14-
}
15-
}
44+
"scripts": {
45+
"bench": "bun bench:bun --warmup 5 --runs 25",
46+
"bench:bun": "hyperfine 'bun src/arktype.ts' 'bun src/valibot.ts' 'bun src/zod.ts'",
47+
"bench:node": "hyperfine --runs 30 'node dist/arktype.js' 'node dist/valibot.js' 'node dist/zod.js'",
48+
"build": "bun scripts/build.ts && echo build success",
49+
"check": "repo-check && bun check:tsc && bun run build && bun check:once && echo check success",
50+
"check:once": "bun bench:bun --runs 1 && echo check:once success",
51+
"check:tsc": "tsc --noEmit && echo check:tsc success"
52+
},
53+
"type": "module",
54+
"version": "1.0.0"
55+
}

0 commit comments

Comments
 (0)