npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zod-monaco/monaco

v2.1.2

Published

Monaco editor adapter with Zod-powered JSON validation, hover, and completions

Readme

@zod-monaco/monaco

Monaco editor adapter with Zod-powered JSON validation, hover tooltips, completions, and AI-safe editing.

Installation

npm install @zod-monaco/monaco @zod-monaco/core zod

Monaco Loading

This package loads Monaco editor from CDN (v0.52.2) via AMD. Use loadMonaco() to load it:

import { loadMonaco } from "@zod-monaco/monaco";

const monaco = await loadMonaco();

Usage

import { loadMonaco, createZodEditorController } from "@zod-monaco/monaco";
import { describeSchema } from "@zod-monaco/core";
import { z } from "zod";

const monaco = await loadMonaco();

const descriptor = describeSchema(
  z.object({ name: z.string(), age: z.number() }),
);

const controller = createZodEditorController({
  monaco,
  descriptor,
  value: '{ "name": "", "age": 0 }',
});

const editor = controller.mount(document.getElementById("editor")!);

controller.onChange((value) => {
  console.log("JSON changed:", value);
});

controller.onValidationChange((result) => {
  console.log("Valid:", result.valid, "Issues:", result.issues);
});

Features

All features are enabled by default and can be toggled:

const controller = createZodEditorController({
  monaco,
  descriptor,
  features: {
    hover: true,        // metadata hover tooltips
    validation: true,   // JSON Schema structural validation
    diagnostics: true,  // Zod runtime validation markers
    completions: true,  // enum value completions
  },
});

Attach to Existing Editor

If you already have a Monaco editor instance, use attachZodToEditor to add Zod features without replacing your setup:

import { attachZodToEditor } from "@zod-monaco/monaco";

const attachment = attachZodToEditor({ monaco, editor, descriptor });

attachment.setDescriptor(anotherDescriptor); // swap schema at runtime
attachment.onValidationChange((result) => console.log(result));
attachment.dispose(); // removes Zod features, does NOT dispose the editor

AI-Safe Editing — prepareJsonEdit

prepareJsonEdit applies an AI-generated value safely: it validates and diffs without touching the editor. The user reviews the diff before anything is written.

import { prepareJsonEdit } from "@zod-monaco/monaco";
import { buildFieldCatalog } from "@zod-monaco/core";

// 1. Build catalog and send to AI (app's responsibility)
const catalog = buildFieldCatalog(descriptor, { currentValue });
const aiResponse = await callYourAI(catalog); // { value: {...} }

// 2. Prepare — editor is NOT modified
const prepared = prepareJsonEdit(editor, descriptor, aiResponse.value);

// 3. Inspect before showing review UI
prepared.valid;             // boolean — passes Zod validation?
prepared.validationIssues;  // ValidationIssue[] — { path, pointer, message }
prepared.diff;              // FieldDiff[] — added / removed / changed
prepared.newText;           // formatted JSON string (use in diff editor)
prepared.stale;             // true if editor was edited during review

// 4. On accept:
if (prepared.stale) {
  // editor changed while reviewing — call prepareJsonEdit again
} else {
  prepared.commit(); // now writes to editor via executeEdits
}

// 5. On reject — nothing to undo, editor was never touched

commit() throws if valid is false. Use { force: true } to override:

prepared.commit({ force: true });

Localization

import { createZodEditorController, locales } from "@zod-monaco/monaco";

createZodEditorController({ monaco, descriptor, locale: locales.tr }); // Turkish
createZodEditorController({
  monaco,
  descriptor,
  locale: { ...locales.en, required: "Pflichtfeld" },
});

Available built-ins: locales.en (default), locales.tr.

Multiple Editors

Multiple editors sharing the same Monaco instance are supported. Each editor's schema is managed through an internal registry — disposing one does not affect others.

API

createZodEditorController(options)

  • mount(element) — mount editor to a DOM element
  • getValue() / setValue(value) — read/write editor content
  • setDescriptor(descriptor) — update schema without remounting
  • onChange(listener) — subscribe to content changes
  • onValidationChange(listener) — subscribe to validation results
  • onCursorPathChange(listener) — subscribe to breadcrumb path changes
  • revealIssue(issue) — navigate to a Zod issue in the editor
  • revealPath(path) — navigate to a path in the editor
  • format() — format JSON (also bound to Ctrl+S)
  • updateOptions(options) — update editor options at runtime
  • getMonaco() / getRawEditor() — escape hatch to native Monaco APIs
  • dispose() — cleanup

prepareJsonEdit(editor, descriptor, newValue)

Returns a PreparedEdit:

| Field | Type | Description | | ----- | ---- | ----------- | | newText | string | Formatted JSON of the proposed value | | valid | boolean | Passes Zod validation | | validationIssues | ValidationIssue[] | { path, pointer, message } per issue | | diff | FieldDiff[] | Added / removed / changed fields | | stale | boolean (getter) | Editor changed since prepare was called | | commit(opts?) | void | Write to editor — throws if invalid or stale |

License

MIT