Skip to content

Commit

Permalink
fix: inconsistencies in README.md and MessageBuilder.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jmike committed Sep 13, 2024
1 parent f8f76d9 commit 280be9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ You may read more on the concept of the `MessageBuilder` further [below](#Messag
#### Example

```typescript
import { z as zod } from 'zod';
import { createMessageBuilder } from 'zod-validation-error';

const messageBuilder = createMessageBuilder({
Expand Down Expand Up @@ -334,7 +333,7 @@ export function parse(

#### Example

For instance, one might want to print the error messages to the console and color any `invalid_string` error with yellow.
For instance, one may want to print `invalid_string` errors to the console in red color.

```typescript
import { z as zod } from 'zod';
Expand All @@ -347,7 +346,7 @@ const myMessageBuilder: MessageBuilder = (issues) => {
// format error message
.map((issue) => {
if (issue.code === zod.ZodIssueCode.invalid_string) {
return chalk.yellow(issue.message);
return chalk.red(issue.message);
}

return issue.message;
Expand All @@ -366,7 +365,7 @@ const zodSchema = zod.object({
try {
zodSchema.parse({
id: 1,
email: 'foobar', // note: invalid string
email: 'foobar', // note: invalid email value
});
} catch (err) {
const validationError = fromError(err, {
Expand Down
2 changes: 1 addition & 1 deletion lib/MessageBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createMessageBuilder } from './MessageBuilder.ts';
import { isZodErrorLike } from './isZodErrorLike.ts';
import { isNonEmptyArray } from './utils/NonEmptyArray.ts';

describe('messageBuilder', () => {
describe('MessageBuilder', () => {
test('handles zod.string() schema errors', () => {
const schema = zod.string().email();

Expand Down

0 comments on commit 280be9b

Please sign in to comment.