-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
282 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,10 @@ https://bundlejs.com/ | |
`rescript-schema` | ||
|
||
```ts | ||
import * as S from "github:DZakh/rescript-schema/artifacts/packages/artifacts/dist/S.mjs"; | ||
import * as S from "rescript-schema@9.0.0-rc.2"; | ||
|
||
// Create login schema with email and password | ||
const loginSchema = S.object({ | ||
const loginSchema = S.schema({ | ||
email: S.email(S.string), | ||
password: S.stringMinLength(S.string, 8), | ||
}); | ||
|
@@ -72,19 +72,22 @@ const loginSchema = S.object({ | |
type LoginData = S.Output<typeof loginSchema>; // { email: string; password: string } | ||
|
||
// Throws the S.Error(`Failed parsing at ["email"]. Reason: Invalid email address`) | ||
loginSchema.parseOrThrow({ email: "", password: "" }); | ||
S.parseOrThrow({ email: "", password: "" }, loginSchema); | ||
|
||
// Returns data as { email: string; password: string } | ||
loginSchema.parseOrThrow({ | ||
email: "[email protected]", | ||
password: "12345678", | ||
}); | ||
S.parseOrThrow( | ||
{ | ||
email: "[email protected]", | ||
password: "12345678", | ||
}, | ||
loginSchema | ||
); | ||
``` | ||
|
||
valibot | ||
|
||
```ts | ||
import * as v from "valibot"; // 1.21 kB | ||
import * as v from "valibot@0.42.1"; // 1.21 kB | ||
|
||
// Create login schema with email and password | ||
const LoginSchema = v.object({ | ||
|
@@ -105,7 +108,7 @@ v.parse(LoginSchema, { email: "[email protected]", password: "12345678" }); | |
zod | ||
|
||
```ts | ||
export * as z from "zod"; // 1.21 kB | ||
import * as z from "zod"; | ||
|
||
// Create login schema with email and password | ||
const LoginSchema = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,12 @@ Highlights: | |
- The **fastest** parsing and validation library in the entire JavaScript ecosystem ([benchmark](https://moltar.github.io/typescript-runtime-type-benchmarks/)) | ||
- Small JS footprint & tree-shakable API ([Comparison with Zod and Valibot](#comparison)) | ||
- Describe transformations in a schema without a performance loss | ||
- Can reverse transformed values to the initial format (serializing) | ||
- Error messages are detailed and easy to understand | ||
- Reverse schema and convert values to the initial format (serializing) | ||
- Detailed and easy to understand error messages | ||
- Support for asynchronous transformations | ||
- Immutable API with both result and exception-based operations | ||
- Immutable API with 100+ different operation combinations | ||
- Easy to create _recursive_ schema | ||
- Opt-in strict mode for object schema to prevent excessive fields. And many more built-in helpers | ||
- Opt-in strict mode for object schema to prevent unknown fields with ability to change it for the whole project | ||
- Opt-in ReScript PPX to generate schema from type definition | ||
|
||
Also, it has declarative API allowing you to use **rescript-schema** as a building block for other tools, such as: | ||
|
@@ -46,12 +46,12 @@ Besides the individual bundle size, the overall size of the library is also sign | |
|
||
At the same time **rescript-schema** is the fastest composable validation library in the entire JavaScript ecosystem. This is achieved because of the JIT approach when an ultra optimized validator is created using `eval`. | ||
|
||
| | [email protected] | Zod@3.23.8 | [email protected] | | ||
| | [email protected] | Zod@3.24.1 | [email protected] | | ||
| ---------------------------------------- | --------------------- | --------------- | -------------- | | ||
| **Total size** (minified + gzipped) | 10.8 kB | 14.2 kB | 10.5 kB | | ||
| **Example size** (minified + gzipped) | 4.38 kB | 12.9 kB | 1.22 kB | | ||
| **Parse with the same schema** | 100,070 ops/ms | 1,325 ops/ms | 3,946 ops/ms | | ||
| **Create schema & parse once** | 195 ops/ms | 121 ops/ms | 2,583 ops/ms | | ||
| **Total size** (minified + gzipped) | 11 kB | 14.8 kB | 10.5 kB | | ||
| **Example size** (minified + gzipped) | 4.45 kB | 13.5 kB | 1.22 kB | | ||
| **Parse with the same schema** | 100,070 ops/ms | 1,277 ops/ms | 3,881 ops/ms | | ||
| **Create schema & parse once** | 179 ops/ms | 112 ops/ms | 2,521 ops/ms | | ||
| **Eval-free** | ❌ | ✅ | ✅ | | ||
| **Codegen-free** (Doesn't need compiler) | ✅ | ✅ | ✅ | | ||
| **Ecosystem** | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️⭐️ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.