typezen
v0.1.0
Published
A collection of TypeScript utilities for safe type checking and inference.
Maintainers
Readme
TypeZen 🔍
A Zen-like Toolkit for Type Checking and Validation "Find Your Type Peace" ✨
🌟 Features
- 100+ Type Guards - Comprehensive type checking functions
- Zero Dependencies - Lightweight and pure TypeScript
- Runtime Validation - Works in both Node.js and browsers
- Image File Validation - Image file type validation
- TypeScript First - Full type inference support
📦 Installation
npm install typezen
# or
yarn add typezen
# or
bun add typezen🚀 Quick Start
import { isEmail, isURL } from 'typezen';
// Validate email
if (isEmail('[email protected]')) {
console.log('Valid email! 📧');
}
// Check URL validity
if (isURL('https://typezen.dev')) {
console.log('Valid URL! 🌐');
}📚 Core Functions
🔢 Primitive Checks
import {
isNumber, isInteger, isFloat, isString,
isBoolean, isSymbol, isPrimitive, isNaNValue
} from 'typezen';
isNumber(42); // true
isFloat(3.14); // true
isString('Zen'); // true
isPositive(6); // true🧰 Object Checks
import {
isObject, isArray, isPromise,
isMap, isSet, isEmpty
} from 'typezen';
isPromise(fetch('/data')); // true
isEmpty({}); // true
isMap(new Map()); // true📂 File & URL Validation
import {
isPNG, isJPEG, isSVG,
isMP3, isMP4, isURL
} from 'typezen';
// File extension check
isPNG('image.png'); // true
// Image file check
await isImageFile(File); // true (checks file contents)
// URL validation
isURL('https://typezen.dev/guide'); // true🎨 Special Formats
import { isHexColor, isEmail, isJSON } from 'typezen';
isHexColor('#ff0044'); // true
isEmail('[email protected]'); // true
isJSON('{"key":"value"}'); // true🧠 Advanced Usage
Custom Error Handling
import { isInteger, TypeValidationError } from 'typezen';
function validateAge(age: unknown): number {
if (!isInteger(age)) {
throw new TypeValidationError('Age must be an integer');
}
return age;
}Combining Validators
import { isString, isEmail, isBetween } from 'typezen';
function isValidUsername(input: unknown): boolean {
return isString(input) &&
isBetween(input.length, 4, 20) &&
!isEmail(input);
}💡 Why TypeZen?
- Runtime Safety: Catch type errors before they crash your app
- TypeScript Optimized: Full type inference and generics support
- Universal: Works in Node.js, Deno, and modern browsers
- Extensible: Create custom type guards easily
🛠️ Contributing
# Clone repo
git clone https://github.com/kiron0/typezen.git
# Install dependencies
bun install
# Build project
bun run build📜 License
MIT © Toufiq Hasan Kiron "The wise validate types before they act" - TypeZen Proverb 🎋
