Skip to content

Commit

Permalink
Update documentation for rescript
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Dec 15, 2024
1 parent 76458c6 commit 65d1140
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 361 deletions.
21 changes: 12 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand All @@ -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({
Expand All @@ -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({
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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** | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️⭐️ |
2 changes: 1 addition & 1 deletion docs/js-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ S.schema(false).parseOrThrow(true);

```rescript
S.setGlobalConfig({
defaultUnknownKeys: Strict,
defaultUnknownKeys: "Strict",
})
```

Expand Down
Loading

0 comments on commit 65d1140

Please sign in to comment.