Jet-Schema offers a straightforward, TypeScript-first approach to schema validation, allowing you to implement your custom validator functions easily. With a lightweight footprint and zero dependencies, it empowers you to validate object properties without being tied to any specific library, ensuring flexibility and control.
jet-schema is a straightforward and efficient TypeScript-first schema validation tool designed to improve your development workflow by allowing you to utilize your own custom validator functions. This zero-dependency library prioritizes simplicity and flexibility, making it easier to validate object properties without the need to consult extensive documentation each time you create or modify a validation function.
Key Features:
- Use Custom Validators: Tailor the validation process by integrating your specific validator functions with object properties, ensuring a seamless validation experience tailored to your project's needs.
- Lightweight Library: The entire package is only 2.2 KB minified and zipped, making it one of the most compact schema validation tools available.
- Type Safety: Achieve robust type safety in both directions—you can impose a schema structure from a predefined type or infer a type directly from a schema.
- Core Functions: Automatically gain access to the essential
.new
,.test
, and.parse
functions with every new schema you create, simplifying the coding process. - Flexible Configuration: Configure settings on both global and local levels, allowing you to define default behaviors and rules for multiple schemas efficiently.
- Cross-Environment Compatibility: Use jet-schema seamlessly on both client-side and server-side applications, enhancing versatility.
- Built-in Support for Enums and Dates: Validate against enum values and transform date representations directly into
Date
objects for easy manipulation.
Example Usage:
import schema from 'utils/schema';
import { isString, isNumber } from 'utils/validators';
interface IUser {
id: number;
name: string;
}
const User = schema<IUser>({
id: isNumber,
name: isString,
});
User.new({ id: 5, name: 'joe' }) // => { id: 5, name: 'joe' }
User.test('asdf') // => false
User.pick('name').test('john') // => true
User.parse('something') // => Error
Benefits of Using jet-schema:
- Reduction in Complexity: Compared to other schema validation libraries, jet-schema offers a more streamlined approach, emphasizing simplicity and user-friendliness.
- Integration without Compilation: Enjoy development without the overhead of a compilation step, ensuring swift deployment in environments that support
ts-node
. - Customizable Error Reporting: Implement your own error handling logic to provide detailed feedback during validation processes.
Conclusion:
If you're looking for a robust, TypeScript-friendly library that empowers you to harness your custom validation logic while keeping your application lightweight and efficient, jet-schema could be the perfect choice for you. Whether developing in TypeScript or JavaScript, integrate this tool into your project and transform the way you handle schema validations.