@anatine/zod-mock
Advanced tools
Comparing version 3.8.2 to 3.8.3
@@ -5,2 +5,4 @@ # Changelog | ||
### [3.8.3](https://github.com/anatine/zod-plugins/compare/zod-mock-3.8.2...zod-mock-3.8.3) (2023-01-17) | ||
### [3.8.2](https://github.com/anatine/zod-plugins/compare/zod-mock-3.8.1...zod-mock-3.8.2) (2023-01-04) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@anatine/zod-mock", | ||
"version": "3.8.2", | ||
"version": "3.8.3", | ||
"description": "Zod auto-mock object generator using Faker at @faker-js/faker", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -111,3 +111,3 @@ "use strict"; | ||
} | ||
const targetStringLength = faker_1.faker.datatype.number(sortedStringOptions); | ||
const targetStringLength = fakerInstance.datatype.number(sortedStringOptions); | ||
/** | ||
@@ -170,6 +170,38 @@ * Returns a random lorem word using `faker.lorem.word(length)`. | ||
if (stringOptions.min != null && val.length < stringOptions.min) { | ||
val = val + faker_1.faker.random.alpha(delta); | ||
val = val + fakerInstance.random.alpha(delta); | ||
} | ||
return val.slice(0, stringOptions.max); | ||
} | ||
function parseBoolean(zodRef, options) { | ||
const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker; | ||
return fakerInstance.datatype.boolean(); | ||
} | ||
function parseDate(zodRef, options) { | ||
const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker; | ||
const { checks = [] } = zodRef._def; | ||
let min; | ||
let max; | ||
checks.forEach((item) => { | ||
switch (item.kind) { | ||
case 'min': | ||
min = item.value; | ||
break; | ||
case 'max': | ||
max = item.value; | ||
break; | ||
} | ||
}); | ||
if (min !== undefined && max !== undefined) { | ||
return fakerInstance.date.between(min, max); | ||
} | ||
else if (min !== undefined && max === undefined) { | ||
return fakerInstance.date.soon(undefined, min); | ||
} | ||
else if (min === undefined && max !== undefined) { | ||
return fakerInstance.date.recent(undefined, max); | ||
} | ||
else { | ||
return fakerInstance.date.soon(); | ||
} | ||
} | ||
function parseNumber(zodRef, options) { | ||
@@ -318,4 +350,4 @@ const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker; | ||
ZodBigInt: parseNumber, | ||
ZodBoolean: () => faker_1.faker.datatype.boolean(), | ||
ZodDate: () => faker_1.faker.date.soon(), | ||
ZodBoolean: parseBoolean, | ||
ZodDate: parseDate, | ||
ZodOptional: parseOptional, | ||
@@ -322,0 +354,0 @@ ZodNullable: parseOptional, |
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
46209
473