Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
This is a small utility library to accompany Zod to enable for Types and Schemas to be defined in one line by creating a Class.
npm install zod-class
The Z
utility function is the swiss army knife in zod-class
- you use it for everything.
import z from "zod";
import { Z } from "zod-class";
// define a class using a zod schema
export class Hello extends Z.class({
name: z.string(),
}) {
get message() {
return `hello ${name}`
}
}
const hello = new Hello({
hello: "sam",
});
const hello = Z(Hello).parse(someVal)
// use method on the instance
const message = hello.message;
// extend a class by first activating it with `Z(Hello)`
export class World extends Z(Hello).extend({
world: z.string()
}) {}
const world = new World({
hello: "world",
world: "hello"
});
It can be annoying to always have redundant declarations for types and schemas:
z.object
declarationz.infer
interface HelloSchema extends z.infer<typeof HelloSchema> {}
const HelloSchema = z.object({
key: z.string(),
});
zod-class
enables this to be achieved in a single line.
It also provides a class that can be instantiated and methods added to.
export class Person extends Z.class({
firstName: z.string(),
lastName: z.string(),
}) {
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
FAQs
Create classes from Zod Object schemas all in one line
We found that zod-class demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.