@anatine/zod-mock
Advanced tools
Comparing version 3.0.3 to 3.0.4
{ | ||
"name": "@anatine/zod-mock", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Zod auto-mock object generator using Faker at @faker-js/faker", | ||
@@ -24,3 +24,3 @@ "main": "src/index.js", | ||
"peerDependencies": { | ||
"@faker-js/faker": "^6.0.0-alpha.6" | ||
"@faker-js/faker": "^6.0.0-alpha.7" | ||
}, | ||
@@ -27,0 +27,0 @@ "typings": "./src/index.d.ts", |
@@ -10,10 +10,10 @@ import { z, ZodTypeAny } from 'zod'; | ||
/** | ||
* This is a mapping of field name to mock generator function. | ||
* This mapping can be used to provide backup mock | ||
* functions for Zod types not yet implemented in {@link WorkerKeys}. | ||
* The functions in this map will only be used if this library | ||
* is unable to find an appropriate mocking function to use. | ||
*/ | ||
backupMocks?: Record<string, (() => any | undefined)>; | ||
* This is a mapping of field name to mock generator function. | ||
* This mapping can be used to provide backup mock | ||
* functions for Zod types not yet implemented in {@link WorkerKeys}. | ||
* The functions in this map will only be used if this library | ||
* is unable to find an appropriate mocking function to use. | ||
*/ | ||
backupMocks?: Record<string, () => any | undefined>; | ||
} | ||
export declare function generateMock<T extends ZodTypeAny>(zodRef: T, options?: GenerateMockOptions): z.infer<typeof zodRef>; |
@@ -18,3 +18,21 @@ "use strict"; | ||
fnName = | ||
lower === lowerCaseKeyName || lower === withoutDashesUnderscores ? keyName : undefined; | ||
lower === lowerCaseKeyName || lower === withoutDashesUnderscores | ||
? keyName | ||
: undefined; | ||
// Skipping depreciated items | ||
const depreciated = { | ||
random: [ | ||
'image', | ||
'number', | ||
'float', | ||
'uuid', | ||
'boolean', | ||
'hexaDecimal', | ||
], | ||
}; | ||
if (Object.keys(depreciated).find((key) => key === sectionKey | ||
? depreciated[key].find((fn) => fn === fnName) | ||
: false)) { | ||
return undefined; | ||
} | ||
if (fnName) { | ||
@@ -27,6 +45,6 @@ const fn = (_a = faker_1.faker[sectionKey]) === null || _a === void 0 ? void 0 : _a[fnName]; | ||
const mock = fn(); | ||
return typeof mock === 'string' | ||
|| typeof mock === 'number' | ||
|| typeof mock === 'boolean' | ||
|| mock instanceof Date | ||
return typeof mock === 'string' || | ||
typeof mock === 'number' || | ||
typeof mock === 'boolean' || | ||
mock instanceof Date | ||
? fnName | ||
@@ -33,0 +51,0 @@ : undefined; |
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
23571
269