Skip to content

Commit

Permalink
docs: fix and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hanayashiki committed May 18, 2023
1 parent 04307ce commit bf88655
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions packages/zod-monaco-reporter/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Zod Monaco Editor
# Zod Monaco Reporter

Render Zod errors in Monaco Editor (the editor used by VSCode).

## Why Monaco Editor

Monaco Editor is gigantic, you may say, but when it comes to complex and large data validated by equally complex Zod schema, it is nice if we can fold up irrelevant blocks,
hover to get error details, and search through the data. All of this comes for free in our everyday VS Code, but you also deserve the same DX in your application. When the data fails validation, render it using `ZodMonacoReporter` and quickly figure out which part goes wrong.

## Installation

```bash
Expand All @@ -10,6 +15,8 @@ pnpm install @monoid-dev/zod-monaco-reporter
yarn add @monoid-dev/zod-monaco-reporter
```

No extra steps for compiling Monaco Editor is needed, because under the hood we use `@monaco-editor/react` which downloads it from [cdn.jsdelivr.net](https://jsdelivr.com).

## Get Started

Consider the following Zod schema:
Expand Down Expand Up @@ -75,8 +82,11 @@ Usage:

Parameters:

1. value: Any value needs validation. Notice that currently the value needs to be JSON serializable or it cannot be displayed correctly.
2. schema?: The zod schema used to verify the `value`.
3. error?: A ZodError for the result. The errors will be rendered regardless of the schema. It is useful if you don't know the schema.
1. value: Any value to validate. Notice that currently the value needs to be JSON serializable or it cannot be displayed correctly.
2. schema?: Optional. The zod schema used to verify the `value`.
3. error?: Optional. A ZodError for the result. The errors will be rendered regardless of the schema. It is useful if you don't know the schema.
4. name?: Optional. The name of the data. It needs to be unique for the Monaco Editor the match each `value` to its own `Model`. If you don't provide one, we generate a random name for you.

Note:

You may prefer using `React.lazy` to load this element as it contains bloated JavaScript.
2 changes: 1 addition & 1 deletion packages/zod-monaco-reporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@monoid-dev/zod-monaco-reporter",
"version": "0.0.4",
"version": "0.0.6",
"type": "commonjs",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down

0 comments on commit bf88655

Please sign in to comment.