New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@anatine/zod-mock

Package Overview
Dependencies
Maintainers
0
Versions
55
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.13.4 to 3.13.5

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

### [3.13.5](https://github.com/anatine/zod-plugins/compare/zod-mock-3.13.4...zod-mock-3.13.5) (2025-01-20)
### Bug Fixes
* **zod-mock:** [[#172](https://github.com/anatine/zod-plugins/issues/172)] add support for mockeryMapper to be used for numbers, dates and booleans ([cd50715](https://github.com/anatine/zod-plugins/commit/cd50715c27d9fdb55a32b208357f07568d7ce82e))
### [3.13.4](https://github.com/anatine/zod-plugins/compare/zod-mock-3.13.3...zod-mock-3.13.4) (2024-03-19)

@@ -7,0 +14,0 @@

2

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

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -76,4 +76,26 @@ "use strict";

}
/**
* Generate mock value from a matching faker function extracted from the mockeryMapper
* @param options mock generator options
* @returns a mock value if a faker function is found in the mockeryMapper passed
*/
function generateMockFromMatchingFaker(options) {
var _a;
// check if there exists a faker for the given key in the mockery mapper
const foundMockeryMapperFaker = (options === null || options === void 0 ? void 0 : options.keyName)
? findMatchingFaker(options === null || options === void 0 ? void 0 : options.keyName, options.faker, options.mockeryMapper)
: undefined;
// generate the mock value from the faker function found
return (_a = foundMockeryMapperFaker === null || foundMockeryMapperFaker === void 0 ? void 0 : foundMockeryMapperFaker()) !== null && _a !== void 0 ? _a : undefined;
}
function parseString(zodRef, options) {
var _a;
// Prioritize user provided generators.
if ((options === null || options === void 0 ? void 0 : options.keyName) && options.stringMap) {
// min/max length handling is not applied here
const generator = options.stringMap[options.keyName];
if (generator) {
return generator();
}
}
const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker;

@@ -93,10 +115,2 @@ const { checks = [] } = zodRef._def;

const lowerCaseKeyName = (_a = options === null || options === void 0 ? void 0 : options.keyName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
// Prioritize user provided generators.
if ((options === null || options === void 0 ? void 0 : options.keyName) && options.stringMap) {
// min/max length handling is not applied here
const generator = options.stringMap[options.keyName];
if (generator) {
return generator();
}
}
const stringOptions = {};

@@ -135,3 +149,4 @@ checks.forEach((item) => {

: fakerInstance.lorem.word({ length: targetStringLength });
const dateGenerator = () => fakerInstance.date.recent().toISOString();
const dateGenerator = () => fakerInstance.date.recent().toISOString().substring(0, 10);
const datetimeGenerator = () => fakerInstance.date.recent().toISOString();
const stringGenerators = {

@@ -145,3 +160,3 @@ default: defaultGenerator,

date: dateGenerator,
dateTime: dateGenerator,
dateTime: datetimeGenerator,
colorHex: fakerInstance.internet.color,

@@ -194,2 +209,7 @@ color: fakerInstance.internet.color,

const fakerInstance = (options === null || options === void 0 ? void 0 : options.faker) || faker_1.faker;
// generate the mock boolean from the mockery mapper
const mockBoolean = generateMockFromMatchingFaker(options);
// verify that the return type of the mock data is a boolean for it to be acceptable
if (typeof mockBoolean === 'boolean')
return mockBoolean;
return fakerInstance.datatype.boolean();

@@ -212,2 +232,7 @@ }

});
// generate the mock date from the mockery mapper
const mockDate = generateMockFromMatchingFaker(options);
// verify that the return type of the mock data is a valid date for it to be acceptable
if (mockDate instanceof Date)
return mockDate;
if (min !== undefined && max !== undefined) {

@@ -242,2 +267,7 @@ return fakerInstance.date.between({ from: min, to: max });

});
// generate the mock number from the mockeryMapper
const mockNumber = generateMockFromMatchingFaker(options);
// verify that the return type of the mock data is a number for it to be acceptable
if (typeof mockNumber === 'number')
return mockNumber;
return fakerInstance.number.int(fakerOptions);

@@ -244,0 +274,0 @@ }

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