Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@anatine/zod-mock

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anatine/zod-mock

Zod auto-mock object generator using Faker at @faker-js/faker

  • 3.8.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
172K
increased by17.01%
Maintainers
1
Weekly downloads
 
Created

What is @anatine/zod-mock?

@anatine/zod-mock is an npm package that provides utilities for generating mock data based on Zod schemas. It is particularly useful for testing and development purposes where you need to create consistent and realistic mock data that adheres to your Zod schema definitions.

What are @anatine/zod-mock's main functionalities?

Generate Mock Data

This feature allows you to generate mock data based on a Zod schema. In this example, a user schema is defined with an id, name, and age. The `mock` function generates a mock user object that adheres to this schema.

const { z } = require('zod');
const { mock } = require('@anatine/zod-mock');

const userSchema = z.object({
  id: z.string().uuid(),
  name: z.string(),
  age: z.number().int().min(18).max(99)
});

const mockUser = mock(userSchema);
console.log(mockUser);

Custom Mock Generators

This feature allows you to set custom mock generators for specific Zod types. In this example, a custom UUID generator is set, and the `mock` function uses this custom generator when creating the mock user object.

const { z } = require('zod');
const { mock, setMock } = require('@anatine/zod-mock');

const userSchema = z.object({
  id: z.string().uuid(),
  name: z.string(),
  age: z.number().int().min(18).max(99)
});

setMock(z.string().uuid(), () => 'custom-uuid');

const mockUser = mock(userSchema);
console.log(mockUser);

Nested Schemas

This feature supports generating mock data for schemas with nested objects. In this example, a user schema includes an address schema, and the `mock` function generates a mock user object with a nested address object.

const { z } = require('zod');
const { mock } = require('@anatine/zod-mock');

const addressSchema = z.object({
  street: z.string(),
  city: z.string(),
  zipCode: z.string().length(5)
});

const userSchema = z.object({
  id: z.string().uuid(),
  name: z.string(),
  age: z.number().int().min(18).max(99),
  address: addressSchema
});

const mockUser = mock(userSchema);
console.log(mockUser);

Other packages similar to @anatine/zod-mock

Keywords

FAQs

Package last updated on 21 Feb 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc