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

@moluoxixi/zod3-to-rule

v0.1.2

Published

`@moluoxixi/zod3-to-rule` 提供可序列化校验规则与 Zod 3 之间的桥接,不依赖 Vue 或任何表单 UI。

Downloads

181

Readme

Zod 3 to Rule

@moluoxixi/zod3-to-rule 提供可序列化校验规则与 Zod 3 之间的桥接,不依赖 Vue 或任何表单 UI。

规则 JSON 是稳定协议。外部输入先通过 parseRuleSet() 严格解析,再使用 compileRules() 编译为 Zod schema、required 元数据和跨字段/custom validator。rulesToZod() 只编译单字段 Zod 能力。

import { compileRules, parseRuleSet } from '@moluoxixi/zod3-to-rule'

const parsed = parseRuleSet({
  version: 1,
  base: { type: 'string' },
  rules: [
    { kind: 'required', message: '请输入邮箱' },
    { kind: 'email', message: '邮箱格式不正确' },
  ],
})

if (parsed.success) {
  const compiled = compileRules(parsed.data)
  compiled.schema.safeParse('[email protected]')
}

支持的基础类型包括 string、number、boolean、date、enum 和 JSON primitive literal。内置规则覆盖字符串长度、regex、email、URL、UUID、数值范围、integer、finite、multipleOf、日期范围、required、基础跨字段比较和命名 custom validator。

zodToRules() 是受限的最佳努力导出器。它支持上述基础类型和 Zod 3 内置 checks,并返回结构化 diagnostics。refinesuperRefine、transform、preprocess、coerce、default 和其他无法由规则 JSON 等价表达的行为不会被静默丢弃;存在不可恢复的 effects 或 coercion 时不会返回 ruleSet