Skip to content

Commit 5c0c57e

Browse files
committed
Improve code example in README and introduction guide
1 parent 562bb71 commit 5c0c57e

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

library/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,26 @@ First you create a schema that describes a structured data set. A schema can be
2929

3030
<!-- prettier-ignore -->
3131
```ts
32-
import * as v from 'valibot'; // 1.24 kB
32+
import * as v from 'valibot'; // 1.31 kB
3333

3434
// Create login schema with email and password
3535
const LoginSchema = v.object({
3636
email: v.pipe(v.string(), v.email()),
3737
password: v.pipe(v.string(), v.minLength(8)),
3838
});
3939

40-
// Infer output TypeScript type of login schema
41-
type LoginData = v.InferOutput<typeof LoginSchema>; // { email: string; password: string }
40+
// Infer output TypeScript type of login schema as
41+
// { email: string; password: string }
42+
type LoginData = v.InferOutput<typeof LoginSchema>;
4243

43-
// Throws error for `email` and `password`
44-
v.parse(LoginSchema, { email: '', password: '' });
44+
// Throws error for email and password
45+
const output1 = v.parse(LoginSchema, { email: '', password: '' });
4546

4647
// Returns data as { email: string; password: string }
47-
v.parse(LoginSchema, { email: '[email protected]', password: '12345678' });
48+
const output2 = v.parse(LoginSchema, {
49+
50+
password: '12345678',
51+
});
4852
```
4953

5054
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](https://valibot.dev/guides/parse-data/).

website/src/routes/guides/(get-started)/introduction/index.mdx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,26 @@ First you create a schema that describes a structured data set. A schema can be
3434

3535
{/* prettier-ignore */}
3636
```ts
37-
import * as v from 'valibot'; // 1.24 kB
37+
import * as v from 'valibot'; // 1.31 kB
3838

3939
// Create login schema with email and password
4040
const LoginSchema = v.object({
4141
email: v.pipe(v.string(), v.email()),
4242
password: v.pipe(v.string(), v.minLength(8)),
4343
});
4444

45-
// Infer output TypeScript type of login schema
46-
type LoginData = v.InferOutput<typeof LoginSchema>; // { email: string; password: string }
45+
// Infer output TypeScript type of login schema as
46+
// { email: string; password: string }
47+
type LoginData = v.InferOutput<typeof LoginSchema>;
4748

48-
// Throws error for `email` and `password`
49-
v.parse(LoginSchema, { email: '', password: '' });
49+
// Throws error for email and password
50+
const output1 = v.parse(LoginSchema, { email: '', password: '' });
5051

5152
// Returns data as { email: string; password: string }
52-
v.parse(LoginSchema, { email: '[email protected]', password: '12345678' });
53+
const output2 = v.parse(LoginSchema, {
54+
55+
password: '12345678',
56+
});
5357
```
5458

5559
Apart from <Link href="/api/parse/">`parse`</Link> I also offer a non-exception-based API with <Link href="/api/safeParse/">`safeParse`</Link> and a type guard function with <Link href="/api/is/">`is`</Link>. You can read more about it <Link href="/guides/parse-data/">here</Link>.

0 commit comments

Comments
 (0)