@anatine/zod-mock
Advanced tools
Comparing version 3.8.0 to 3.8.1
@@ -5,2 +5,4 @@ # Changelog | ||
### [3.8.1](https://github.com/anatine/zod-plugins/compare/zod-mock-3.8.0...zod-mock-3.8.1) (2023-01-01) | ||
## [3.8.0](https://github.com/anatine/zod-plugins/compare/zod-mock-3.7.0...zod-mock-3.8.0) (2022-12-12) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@anatine/zod-mock", | ||
"version": "3.8.0", | ||
"version": "3.8.1", | ||
"description": "Zod auto-mock object generator using Faker at @faker-js/faker", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -32,3 +32,3 @@ import { faker } from '@faker-js/faker'; | ||
/** | ||
* Set a seed for random generation within the mock library | ||
* Set a seed for random generation | ||
*/ | ||
@@ -35,0 +35,0 @@ seed?: number | number[]; |
@@ -74,2 +74,3 @@ "use strict"; | ||
const generator = new randExp(regexCheck.regex); | ||
generator.randInt = (min, max) => fakerInstance.datatype.number({ min, max }); | ||
const max = checks.find((check) => check.kind === 'max'); | ||
@@ -235,19 +236,19 @@ if (max && 'value' in max && typeof max.value === 'number') { | ||
} | ||
function parseEnum(zodRef) { | ||
function parseEnum(zodRef, options) { | ||
const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker; | ||
const values = zodRef._def.values; | ||
const pick = Math.floor(Math.random() * values.length); | ||
return values[pick]; | ||
return fakerInstance.helpers.arrayElement(values); | ||
} | ||
function parseDiscriminatedUnion(zodRef, options) { | ||
const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker; | ||
// Map the options to various possible union cases | ||
const potentialCases = [...zodRef._def.options.values()]; | ||
const pick = Math.floor(Math.random() * potentialCases.length); | ||
const mocked = potentialCases[pick]; | ||
const mocked = fakerInstance.helpers.arrayElement(potentialCases); | ||
return generateMock(mocked, options); | ||
} | ||
function parseNativeEnum(zodRef) { | ||
function parseNativeEnum(zodRef, options) { | ||
const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker; | ||
const { values } = zodRef._def; | ||
const pick = Math.floor(Math.random() * Object.values(values).length); | ||
const key = Array.from(Object.keys(values))[pick]; | ||
return values[values[key]]; | ||
const value = fakerInstance.helpers.arrayElement(values); | ||
return values[value]; | ||
} | ||
@@ -267,4 +268,5 @@ function parseLiteral(zodRef) { | ||
// Map the options to various possible mock values | ||
const mockOptions = zodRef._def.options.map((option) => generateMock(option, options)); | ||
return fakerInstance.helpers.arrayElement(mockOptions); | ||
const potentialCases = [...zodRef._def.options.values()]; | ||
const mocked = fakerInstance.helpers.arrayElement(potentialCases); | ||
return generateMock(mocked, options); | ||
} | ||
@@ -271,0 +273,0 @@ function parseZodIntersection(zodRef, options) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44036
441