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 - npm Package Compare versions

Comparing version 3.0.4 to 3.1.0

10

package.json
{
"name": "@anatine/zod-mock",
"version": "3.0.4",
"version": "3.1.0",
"description": "Zod auto-mock object generator using Faker at @faker-js/faker",

@@ -24,8 +24,8 @@ "main": "src/index.js",

"peerDependencies": {
"@faker-js/faker": "^6.0.0-alpha.7"
"@faker-js/faker": "^6.0.0-beta.0",
"randexp": "^0.5.3",
"zod": "^3.13.4"
},
"typings": "./src/index.d.ts",
"dependencies": {
"zod": "^3.11.6"
}
"dependencies": {}
}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -6,2 +6,3 @@ "use strict";

const faker_1 = require("@faker-js/faker");
const randExp = require("randexp");
function parseObject(zodRef, options) {

@@ -15,3 +16,3 @@ return Object.keys(zodRef.shape).reduce((carry, key) => (Object.assign(Object.assign({}, carry), { [key]: generateMock(zodRef.shape[key], Object.assign(Object.assign({}, options), { keyName: key })) })), {});

const sectionName = Object.keys(faker_1.faker).find((sectionKey) => {
return Object.keys(faker_1.faker[sectionKey]).find((fnKey) => {
return Object.keys(faker_1.faker[sectionKey] || {}).find((fnKey) => {
var _a;

@@ -40,2 +41,3 @@ const lower = fnKey.toLowerCase();

if (fnName) {
// TODO: it would be good to clean up these type castings
const fn = (_a = faker_1.faker[sectionKey]) === null || _a === void 0 ? void 0 : _a[fnName];

@@ -70,2 +72,12 @@ if (typeof fn === 'function') {

const { checks = [] } = zodRef._def;
const regexCheck = checks.find((check) => check.kind === 'regex');
if (regexCheck && 'regex' in regexCheck) {
const generator = new randExp(regexCheck.regex);
const max = checks.find((check) => check.kind === 'max');
if (max && 'value' in max) {
generator.max = max.value;
}
const genRegString = generator.gen();
return genRegString;
}
const lowerCaseKeyName = (_a = options === null || options === void 0 ? void 0 : options.keyName) === null || _a === void 0 ? void 0 : _a.toLowerCase();

@@ -202,2 +214,7 @@ // Prioritize user provided generators.

}
function parseUnion(zodRef, options) {
// Map the options to various possible mock values
const mockOptions = zodRef._def.options.map((option) => generateMock(option, options));
return faker_1.faker.helpers.randomize(mockOptions);
}
const workerMap = {

@@ -219,2 +236,3 @@ ZodObject: parseObject,

ZodEffects: parseTransform,
ZodUnion: parseUnion,
};

@@ -221,0 +239,0 @@ function generateMock(zodRef, options) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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