{"id":19736507,"url":"https://github.com/soc221b/zod-schema-faker","last_synced_at":"2025-04-06T20:09:15.990Z","repository":{"id":39000781,"uuid":"478904682","full_name":"soc221b/zod-schema-faker","owner":"soc221b","description":"Generate mock data from zod schemas. Powered by @faker-js/faker and randexp.js.","archived":false,"fork":false,"pushed_at":"2025-03-27T06:36:05.000Z","size":1312,"stargazers_count":46,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T08:32:51.494Z","etag":null,"topics":["fake","fixture","mock","stub","zod"],"latest_commit_sha":null,"homepage":"https://stackblitz.com/edit/zod-schema-faker?file=src%2Fmain.ts","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soc221b.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"buy_me_a_coffee":"iendeavor"}},"created_at":"2022-04-07T08:58:40.000Z","updated_at":"2025-03-27T06:36:09.000Z","dependencies_parsed_at":"2023-11-29T01:30:14.762Z","dependency_job_id":"2141b6c3-16b1-4f95-a45b-b11589018eac","html_url":"https://github.com/soc221b/zod-schema-faker","commit_stats":{"total_commits":287,"total_committers":4,"mean_commits":71.75,"dds":0.4738675958188153,"last_synced_commit":"fd7bf70315183b9ed578883224d9708b1388573b"},"previous_names":["soc221b/zod-schema-faker"],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fzod-schema-faker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fzod-schema-faker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fzod-schema-faker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soc221b%2Fzod-schema-faker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soc221b","download_url":"https://codeload.github.com/soc221b/zod-schema-faker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247543589,"owners_count":20955865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fake","fixture","mock","stub","zod"],"created_at":"2024-11-12T01:07:21.465Z","updated_at":"2025-04-06T20:09:15.969Z","avatar_url":"https://github.com/soc221b.png","language":"TypeScript","funding_links":["https://buymeacoffee.com/iendeavor"],"categories":[],"sub_categories":[],"readme":"# zod-schema-faker\n\n\u003e Generate mock data from [zod](https://github.com/colinhacks/zod) schemas. Powered by\n\u003e [@faker-js/faker](https://github.com/faker-js/faker) and [randexp.js](https://github.com/fent/randexp.js).\n\n[![CI](https://github.com/soc221b/zod-schema-faker/actions/workflows/ci.yml/badge.svg)](https://github.com/soc221b/zod-schema-faker/actions/workflows/ci.yml)\n[![NPM](https://img.shields.io/npm/v/zod-schema-faker.svg?label=NPM\u0026color=brightgreen)](https://www.npmjs.com/package/zod-schema-faker)\n\nFeatures\n\n- Support almost all zod types\n- Support for custom zod types\n- Extensive tests\n\n## Installation\n\n```sh\nnpm install --save-dev zod-schema-faker\n```\n\n## Usage\n\nBuilt-in zod types:\n\n```ts\nimport { z } from 'zod'\nimport { install, fake } from 'zod-schema-faker'\n\n// define a zod schema\nconst schema = z.number()\n\n// call install() to register fakers\ninstall()\n\n// generate fake data based on schema\nconst data = fake(schema)\n```\n\nCustom zod types:\n\n```ts\nimport { z } from 'zod'\nimport { installCustom, fake, getFaker, ZodTypeFaker } from 'zod-schema-faker'\n\n// define a custom zod schema\nconst pxSchema = z.custom\u003c`${number}px`\u003e(val =\u003e {\n  return typeof val === 'string' ? /^\\d+px$/.test(val) : false\n})\n\n// define a custom faker\nclass ZodPxFaker extends ZodTypeFaker\u003ctypeof pxSchema\u003e {\n  fake(): `${number}px` {\n    return `${getFaker().number.int({ min: 0 })}px`\n  }\n}\n\n// call installCustom() to register custom fakers\ninstallCustom(pxSchema, ZodPxFaker)\n\n// generate fake data based on schema\nconst data = fake(pxSchema)\n```\n\n## API\n\nCore APIs\n\n- `function install(): void`: Install fakers for built-in types, must be called before using `fake`.\n- `function fake\u003cT extends z.ZodType\u003e(schema: T): z.infer\u003cT\u003e`: Generate fake data based on schema.\n- `function seed(value?: number): void`: Sets the seed to use.\n- `class ZodSchemaFakerError`\n\nRandom Utility APIs\n\n- `function setFaker(faker: Faker): void`: Use given faker instance instead of the default one.\n- `function getFaker(): Faker`: Get the faker instance. Defaults to `fakerEN`.\n- `function randexp(pattern: string | RegExp, flags?: string): string`: Create random strings that match a given regular\n  expression.\n\nCustomization APIs - see [example](./tests/zod-custom-faker.test.ts) for details\n\n- `class ZodTypeFaker`: Base class for fakers.\n- `function installCustom\u003cT extends z.ZodTypeAny\u003e(schema: T, faker: typeof ZodTypeFakerConcrete\u003cT\u003e): void`: Install\n  fakers for custom schemas, must be called before using `fake`.\n\n## Supported Zod Types\n\n- methods\n  - ✅ .and\n  - ✅ .array\n  - ✅ .brand\n  - ✅ .catch\n  - ✅ .default\n  - ✅ .nullable\n  - ✅ .nullish\n  - ✅ .optional\n  - ✅ .or\n  - ✅ .pipe\n  - ✅ .promise\n  - ✅ .readonly\n  - ❌ .refine\n  - ❌ .superRefine\n  - ✅ .transform\n- ✅ z.any\n- ✅ z.array\n- ✅ z.bigint\n- ✅ z.boolean\n- ✅ z.custom: see [example](./tests/zod-custom-faker.test.ts) for details.\n- ✅ z.date\n- ✅ z.discriminatedUnion\n- ✅ z.enum\n- ✅ z.instanceof: see [example](./tests/zod-instanceof-faker.test.ts) for details.\n- ✅ z.intersection\n- ✅ z.function\n- ✅ z.lazy\n- ✅ z.literal\n- ✅ z.map\n- ✅ z.nan\n- ✅ z.nativeEnum\n- ✅ z.never: always throws an error\n- ✅ z.null\n- ✅ z.number\n- ✅ z.object\n- ✅ z.preprocess[^2]\n- ✅ z.promise\n- ✅ z.record\n- ✅ z.set\n- ✅ z.string[^1]\n- ✅ z.symbol\n- ✅ z.tuple\n- ✅ z.undefined\n- ✅ z.union\n- ✅ z.unknown\n- ✅ z.void\n\n[^1]: Not compatible with other validations. For example, `z.length(5)` is ignored in `z.base64().length(5)`.\n\n[^2]: Not applicable, ignored\n\n## Comparison\n\n### @anatine/zod-mock\n\nhttps://github.com/anatine/zod-plugins/tree/main/packages/zod-mock\n\n- Excels at generating realistic data for `z.string`. For instance, `z.object({ image: z.string() })` will produce a URL\n  string.\n- Lacks support for some basic zod types such as `z.any`, `z.default`, `z.tuple`, etc.\n\n### zod-fixture\n\nhttps://github.com/timdeschryver/zod-fixture\n\n- Provides support for custom zod types.\n- Occasionally generates invalid mocked data. For example, calling with the function generated from\n  `z.function(z.tuple([]), z.boolean())` did not return a boolean value.\n\n### Inactive Libraries\n\n- https://github.com/dipasqualew/zod-mocking\n- https://github.com/LorisSigrist/zocker\n- https://github.com/ItMaga/zodock\n\n## About\n\nDistributed under the MIT license. See LICENSE for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoc221b%2Fzod-schema-faker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoc221b%2Fzod-schema-faker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoc221b%2Fzod-schema-faker/lists"}