Dhi Typescript logo

Dhi Typescript

Community
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.

Overview

Publisherjustrach
Repositorydhi
Skill namedhi-typescript
Stars
385
Forks
6
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by justrach on GitHub. Read the source before you install it.

Installation

Install the Dhi Typescript AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

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
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Dhi Typescript in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Dhi Typescript on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Dhi Typescript is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

Frequently asked questions

What does the Dhi Typescript AI skill do?

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.

Why use Dhi Typescript on TypingMind?

Because you install it once and use it with any model. Dhi Typescript is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Dhi Typescript in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/justrach/dhi/tree/main/js-bindings/dhi-typescript. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Dhi Typescript?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Dhi Typescript?

As many as you like. As long as a model supports skills, you can use Dhi Typescript with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Dhi Typescript AI skill free?

Yes. It is published on GitHub by justrach under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇