DHI is a high-performance TypeScript validation library powered by WebAssembly. Named after the Sanskrit word धि (Dhi), meaning "intellect" or "wisdom," DHI embodies the smart, precise, and efficient data validation you need in modern applications.
धि: Intellect, understanding, wisdom.
DHI is designed to be fast, type-safe, and easy to use—offering a familiar API similar to Zod, but with performance that leaves it far behind. Benchmarks on complex validations with new types (1,000,000 items) show(Benchmarks are available in the benchmarks folder):
- Results:
- DHI: 2661.79ms
- Zod: 5832.30ms
- Validations per second:
- DHI: 375,687
- Zod: 175,360
DHI leverages WebAssembly to accelerate validation tasks, ensuring that even complex validations with new types are handled with remarkable speed.
- WebAssembly-Powered Validation: Ultra-fast performance using WebAssembly.
- TypeScript-First Design: Seamless integration with TypeScript for strong typing.
- Familiar API: Similar to Zod, making it easy to adopt.
- Batch Validation Support: Validate large batches of items efficiently.
- Rich Type System: Supports a wide array of types.
npm install dhi
bun add dhi
import { dhi } from 'dhi';
const UserSchema = await dhi.object({
name: dhi.string(),
age: dhi.number(),
email: dhi.string(),
tags: dhi.array(dhi.string())
});
const result = UserSchema.validate({
name: "John",
age: 30,
email: "john@example.com",
tags: ["user", "admin"]
});
console.log(result.success);
string
number
boolean
date
bigint
symbol
array
object
record
enum
undefined
null
void
any
unknown
never
- Optional Fields:
dhi.optional(dhi.string())
- Nullable Fields:
dhi.nullable(dhi.number())
- Record Types:
dhi.record(dhi.string())
- Batch Validation: Use
UserSchema.validate_batch(items)
for validating multiple items at once.
DHI is built with performance in mind. It uses WebAssembly to validate data at speeds significantly faster than traditional JavaScript validators. In our benchmarks on complex validations with new types:
-
Benchmark 1 (1,000,000 items):
- DHI: 2661.79ms
- Zod: 5832.30ms
- Validations per second: DHI: 375,687 vs. Zod: 175,360
-
Benchmark 2 (1,000,000 items):
- DHI: 2885.60ms
- Validations per second: DHI: 346,548
These results showcase the performance edge DHI offers, especially for applications requiring massive data validations.
This project is licensed under the Apache 2.0 License.
Rach Pradhan
For more information, bug reports, or contributions, please visit the GitHub repository.
🌟 DHI: Where Sanskrit wisdom meets modern TypeScript validation - delivering unmatched speed, precision, and reliability for your applications.