Package Exports
- dhi
- dhi/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dhi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
DHI
π DHI - High Performance TypeScript Validation
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.
Features
- 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.
π₯ Installation
npm install dhibun add dhiπ¨ Basic Usage
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);ποΈ Supported Types
stringnumberbooleandatebigintsymbolarrayobjectrecordenumundefinednullvoidanyunknownnever
π Advanced Features
- 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.
Performance
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.
License
This project is licensed under the Apache 2.0 License.
Author
Rach Pradhan
Repository
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.