Dhi Typescript 标志

Dhi Typescript

社区
justrach
dhi-typescript

Ultra-fast validation library for TypeScript/JavaScript (77x faster than Zod). Use when building validated schemas for APIs, forms, or data processing. Provides Zod 4-compatible API with WASM-powered SIMD validation.

概览

发布者justrach
代码仓库dhi
技能名称dhi-typescript
星标数
385
复刻数
6
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 justrach 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Dhi Typescript AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/justrach/dhi/tree/main/js-bindings/dhi-typescript
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/justrach/dhi.git /tmp/dhi
mkdir -p .claude/skills
cp -r /tmp/dhi/js-bindings/dhi-typescript .claude/skills/dhi-typescript
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Dhi Typescript,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Dhi Typescript。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Dhi Typescript 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

dhi - Ultra-Fast TypeScript Validation

Overview

dhi is a high-performance validation library for TypeScript and JavaScript, powered by Zig-compiled WebAssembly with SIMD optimizations. It provides a Zod 4-compatible API while being 77x faster for validation operations.

Use dhi when you need:

  • Fast schema validation for APIs
  • Form validation in frontend apps
  • Data parsing and transformation
  • Type-safe runtime validation

Installation

bash
# npm
npm install dhi

# bun
bun add dhi

# pnpm
pnpm add dhi

Quick Start

Basic Schema

typescript
import { z } from 'dhi';

const UserSchema = z.object({
  name: z.string().min(1).max(100),
  age: z.number().int().min(0).max(120),
  email: z.string().email(),
  score: z.number().default(0),
});

type User = z.infer<typeof UserSchema>;

// Parse and validate
const user = UserSchema.parse({
  name: "Alice",
  age: 25,
  email: "alice@example.com"
});

Safe Parsing

typescript
const result = UserSchema.safeParse(data);

if (result.success) {
  console.log(result.data);
} else {
  console.log(result.error.issues);
}

Schema Types

Primitives

typescript
z.string()
z.number()
z.boolean()
z.bigint()
z.date()
z.undefined()
z.null()
z.void()
z.any()
z.unknown()
z.never()

String Validations

typescript
z.string()
  .min(1)              // Minimum length
  .max(100)            // Maximum length
  .length(10)          // Exact length
  .email()             // Email format
  .url()               // URL format
  .uuid()              // UUID format
  .cuid()              // CUID format
  .cuid2()             // CUID2 format
  .ulid()              // ULID format
  .regex(/pattern/)    // Custom regex
  .includes("text")    // Contains substring
  .startsWith("pre")   // Starts with
  .endsWith("suf")     // Ends with
  .datetime()          // ISO datetime
  .ip()                // IP address
  .trim()              // Trim whitespace
  .toLowerCase()       // Convert to lowercase
  .toUpperCase()       // Convert to uppercase

Number Validations

typescript
z.number()
  .int()               // Integer only
  .positive()          // > 0
  .nonnegative()       // >= 0
  .negative()          // < 0
  .nonpositive()       // <= 0
  .min(0)              // >= value
  .max(100)            // <= value
  .gt(0)               // > value
  .lt(100)             // < value
  .multipleOf(5)       // Multiple of
  .finite()            // No Infinity
  .safe()              // Safe integer range

Objects

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

// Optional fields
const PartialPerson = PersonSchema.partial();

// Required fields
const RequiredPerson = PersonSchema.required();

// Pick specific fields
const NameOnly = PersonSchema.pick({ name: true });

// Omit fields
const NoAge = PersonSchema.omit({ age: true });

// Extend schema
const Employee = PersonSchema.extend({
  employeeId: z.string(),
});

// Merge schemas
const Combined = PersonSchema.merge(AddressSchema);

// Strict mode (no extra keys)
const StrictPerson = PersonSchema.strict();

// Passthrough (keep extra keys)
const LoosePerson = PersonSchema.passthrough();

Arrays

typescript
z.array(z.string())
  .min(1)              // Minimum items
  .max(10)             // Maximum items
  .length(5)           // Exact length
  .nonempty()          // At least one item

// Tuples
z.tuple([z.string(), z.number()])

Unions and Intersections

typescript
// Union (OR)
const StringOrNumber = z.union([z.string(), z.number()]);

// Discriminated union
const Event = z.discriminatedUnion("type", [
  z.object({ type: z.literal("click"), x: z.number(), y: z.number() }),
  z.object({ type: z.literal("scroll"), offset: z.number() }),
]);

// Intersection (AND)
const Combined = z.intersection(SchemaA, SchemaB);

Enums and Literals

typescript
// String enum
const Status = z.enum(["pending", "active", "archived"]);

// Native enum
enum Direction { Up, Down, Left, Right }
const DirectionSchema = z.nativeEnum(Direction);

// Literal
const One = z.literal(1);
const Hello = z.literal("hello");

Optional and Nullable

typescript
z.string().optional()     // string | undefined
z.string().nullable()     // string | null
z.string().nullish()      // string | null | undefined

Transformations

typescript
// Transform value
const Trimmed = z.string().transform(s => s.trim());

// Coerce types
z.coerce.string()   // Convert to string
z.coerce.number()   // Convert to number
z.coerce.boolean()  // Convert to boolean
z.coerce.date()     // Convert to Date

// Preprocess
const Schema = z.preprocess(
  (val) => String(val).trim(),
  z.string()
);

// Pipe (chain schemas)
const Pipeline = z.string()
  .transform(s => s.split(","))
  .pipe(z.array(z.string()));

Records and Maps

typescript
// Record (object with dynamic keys)
z.record(z.string())              // Record<string, string>
z.record(z.string(), z.number()) // Record<string, number>

// Map
z.map(z.string(), z.number())

Refinements

typescript
// Custom validation
const EvenNumber = z.number().refine(
  n => n % 2 === 0,
  { message: "Must be even" }
);

// Superrefine for complex validation
const PasswordSchema = z.object({
  password: z.string(),
  confirm: z.string(),
}).superRefine((data, ctx) => {
  if (data.password !== data.confirm) {
    ctx.addIssue({
      code: z.ZodIssueCode.custom,
      message: "Passwords don't match",
      path: ["confirm"],
    });
  }
});

Error Handling

typescript
try {
  UserSchema.parse(invalidData);
} catch (error) {
  if (error instanceof z.ZodError) {
    console.log(error.issues);
    console.log(error.format());
    console.log(error.flatten());
  }
}

Type Inference

typescript
// Infer input type
type UserInput = z.input<typeof UserSchema>;

// Infer output type (after transforms)
type UserOutput = z.output<typeof UserSchema>;

// Shorthand for output
type User = z.infer<typeof UserSchema>;

Performance

dhi is 77x faster than Zod for validation operations:

OperationdhiZodSpeedup
String formats46M/sec0.6M/sec77x
Object validationFastSlower~50x
Array validationFastSlower~40x

Next.js Integration

typescript
// app/api/users/route.ts
import { z } from 'dhi';
import { NextResponse } from 'next/server';

const CreateUserSchema = z.object({
  name: z.string().min(1),
  email: z.string().email(),
});

export async function POST(request: Request) {
  const body = await request.json();
  const result = CreateUserSchema.safeParse(body);

  if (!result.success) {
    return NextResponse.json(
      { error: result.error.flatten() },
      { status: 400 }
    );
  }

  // result.data is fully typed
  return NextResponse.json({ user: result.data });
}

Edge Runtime Compatible

dhi works in edge runtimes (Vercel Edge, Cloudflare Workers) with a tiny 28KB WASM bundle.

typescript
export const runtime = 'edge';

import { z } from 'dhi';
// Works in edge functions!

Migration from Zod

dhi is designed as a drop-in replacement:

typescript
// Before (Zod)
import { z } from 'zod';

// After (dhi)
import { z } from 'dhi';

Most Zod 4 code works unchanged with dhi.


When to Use

Use dhi when:

  • Building high-performance APIs
  • Need fast form validation
  • Working with edge runtimes
  • Processing large volumes of data
  • Need Zod compatibility with better performance

Resources

常见问题

Dhi Typescript AI 技能有什么作用?

Ultra-fast validation library for TypeScript/JavaScript (77x faster than Zod). Use when building validated schemas for APIs, forms, or data processing. Provides Zod 4-compatible API with WASM-powered SIMD validation.

为什么在 TypingMind 中使用 Dhi Typescript?

因为您只需安装一次,就能搭配任何模型使用。Dhi Typescript 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Dhi Typescript?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/justrach/dhi/tree/main/js-bindings/dhi-typescript。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Dhi Typescript?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Dhi Typescript 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Dhi Typescript 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Dhi Typescript AI 技能免费吗?

是的。justrach 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇