Socket
Socket
Sign inDemoInstall

zod-form-data

Package Overview
Dependencies
1
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

1

browser/helpers.d.ts

@@ -59,2 +59,3 @@ import { z, ZodArray, ZodEffects, ZodNumber, ZodObject, ZodString, ZodTypeAny } from "zod";

};
export declare const json: <T extends z.ZodTypeAny>(schema: T) => z.ZodEffects<T, T["_output"], T["_input"]>;
/**

@@ -61,0 +62,0 @@ * This helper takes the place of the `z.object` at the root of your schema.

@@ -76,2 +76,11 @@ import { z, ZodType, } from "zod";

const entries = z.array(z.tuple([z.string(), z.any()]));
const safeParseJson = (jsonString) => {
try {
return JSON.parse(jsonString);
}
catch {
return jsonString;
}
};
export const json = (schema) => z.preprocess(preprocessIfValid(z.union([stripEmpty, z.string().transform((val) => safeParseJson(val))])), schema);
/**

@@ -78,0 +87,0 @@ * This helper takes the place of the `z.object` at the root of your schema.

@@ -59,2 +59,3 @@ import { z, ZodArray, ZodEffects, ZodNumber, ZodObject, ZodString, ZodTypeAny } from "zod";

};
export declare const json: <T extends z.ZodTypeAny>(schema: T) => z.ZodEffects<T, T["_output"], T["_input"]>;
/**

@@ -61,0 +62,0 @@ * This helper takes the place of the `z.object` at the root of your schema.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formData = exports.repeatableOfType = exports.repeatable = exports.file = exports.checkbox = exports.numeric = exports.text = void 0;
exports.formData = exports.json = exports.repeatableOfType = exports.repeatable = exports.file = exports.checkbox = exports.numeric = exports.text = void 0;
const zod_1 = require("zod");

@@ -85,2 +85,12 @@ const stripEmpty = zod_1.z.literal("").transform(() => undefined);

const entries = zod_1.z.array(zod_1.z.tuple([zod_1.z.string(), zod_1.z.any()]));
const safeParseJson = (jsonString) => {
try {
return JSON.parse(jsonString);
}
catch {
return jsonString;
}
};
const json = (schema) => zod_1.z.preprocess(preprocessIfValid(zod_1.z.union([stripEmpty, zod_1.z.string().transform((val) => safeParseJson(val))])), schema);
exports.json = json;
/**

@@ -87,0 +97,0 @@ * This helper takes the place of the `z.object` at the root of your schema.

2

package.json
{
"name": "zod-form-data",
"version": "1.1.1",
"version": "1.2.0",
"browser": "./browser/index.js",

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

@@ -121,2 +121,18 @@ import {

const safeParseJson = (jsonString: string) => {
try {
return JSON.parse(jsonString);
} catch {
return jsonString;
}
};
export const json = <T extends ZodTypeAny>(schema: T): ZodEffects<T> =>
z.preprocess(
preprocessIfValid(
z.union([stripEmpty, z.string().transform((val) => safeParseJson(val))])
),
schema
);
/**

@@ -123,0 +139,0 @@ * This helper takes the place of the `z.object` at the root of your schema.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc