1.7.1 • Published 22 days ago

ts-zod-decorators v1.7.1

Weekly downloads
-
License
ISC
Repository
-
Last release
22 days ago

Summary

This repository enhances the functionality of the Zod library by providing validation decorators. Zod is a TypeScript-first schema declaration and validation library. The added decorators make it easier to validate data against predefined schemas in TypeScript projects.

Installation

npm install ts-zod-decorators

Input validation

import { ZodInput, Validate } from 'ts-zod-decorators';
import * as z from 'zod';

const schema = z.object({ name: z.string(), age: z.number() });

class Foo {
	@Validate
	public bar(@ZodInput(schema) input: z.infer<typeof schema>) {}
}

Output validation

import { ZodInput, Validate, ZodOutput } from 'ts-zod-decorators';
import * as z from 'zod';

const schema = z.object({ name: z.string(), age: z.number() });

class Foo {
	@Validate
	@ZodOutput(schema)
	public bar(input: unknown): Promise<z.infer<schema>> {
		return Promise.resolve({ name: 'foo', age: 1 });
	}
}
1.7.1

22 days ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago