Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-to-zod

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-zod - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

5

dist/cjs/cli.js

@@ -40,2 +40,6 @@ #!/usr/bin/env node

},
noImport: {
shortHand: "ni",
description: "Removes the `import { z } from 'zod';` or equivalent from the output"
},
};

@@ -50,2 +54,3 @@ async function main() {

module: args.module || "esm",
noImport: args.noImport
});

@@ -52,0 +57,0 @@ if (args.output) {

20

dist/cjs/jsonSchemaToZod.js

@@ -5,3 +5,3 @@ "use strict";

const parseSchema_js_1 = require("./parsers/parseSchema.js");
const jsonSchemaToZod = (schema, { module, name, type, ...rest } = {}) => {
const jsonSchemaToZod = (schema, { module, name, type, noImport, ...rest } = {}) => {
if (type && (!name || module !== "esm")) {

@@ -18,12 +18,18 @@ throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");

if (module === "cjs") {
result = `const { z } = require("zod")
result = `module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
`;
if (!noImport) {
result = `const { z } = require("zod")
module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
`;
${result}`;
}
}
else if (module === "esm") {
result = `import { z } from "zod"
result = `export ${name ? `const ${name} =` : `default`} ${result}
`;
if (!noImport) {
result = `import { z } from "zod"
export ${name ? `const ${name} =` : `default`} ${result}
`;
${result}`;
}
}

@@ -30,0 +36,0 @@ else if (name) {

@@ -38,2 +38,6 @@ #!/usr/bin/env node

},
noImport: {
shortHand: "ni",
description: "Removes the `import { z } from 'zod';` or equivalent from the output"
},
};

@@ -48,2 +52,3 @@ async function main() {

module: args.module || "esm",
noImport: args.noImport
});

@@ -50,0 +55,0 @@ if (args.output) {

import { parseSchema } from "./parsers/parseSchema.js";
export const jsonSchemaToZod = (schema, { module, name, type, ...rest } = {}) => {
export const jsonSchemaToZod = (schema, { module, name, type, noImport, ...rest } = {}) => {
if (type && (!name || module !== "esm")) {

@@ -14,12 +14,18 @@ throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");

if (module === "cjs") {
result = `const { z } = require("zod")
result = `module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
`;
if (!noImport) {
result = `const { z } = require("zod")
module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
`;
${result}`;
}
}
else if (module === "esm") {
result = `import { z } from "zod"
result = `export ${name ? `const ${name} =` : `default`} ${result}
`;
if (!noImport) {
result = `import { z } from "zod"
export ${name ? `const ${name} =` : `default`} ${result}
`;
${result}`;
}
}

@@ -26,0 +32,0 @@ else if (name) {

import { Options, JsonSchema } from "./Types.js";
export declare const jsonSchemaToZod: (schema: JsonSchema, { module, name, type, ...rest }?: Options) => string;
export declare const jsonSchemaToZod: (schema: JsonSchema, { module, name, type, noImport, ...rest }?: Options) => string;

@@ -56,2 +56,3 @@ export type Serializable = {

type?: boolean | string;
noImport?: boolean;
};

@@ -58,0 +59,0 @@ export type Refs = Options & {

@@ -22,3 +22,3 @@ export type Param = {

[key: number]: string;
} ? T[name]["value"][number] : boolean) | (T[name]["required"] extends string | true ? never : undefined);
} ? T[name]["value"][number] : T[name]["value"] extends never ? boolean : boolean) | (T[name]["required"] extends string | true ? never : undefined);
};

@@ -25,0 +25,0 @@ export declare function parseArgs<T extends Params>(params: T, args: string[], help?: boolean | string): InferReturnType<T>;

{
"name": "json-schema-to-zod",
"version": "2.2.0",
"version": "2.3.0",
"description": "Converts JSON schema objects or files into Zod schemas",

@@ -5,0 +5,0 @@ "types": "./dist/types/index.d.ts",

@@ -38,10 +38,11 @@ # Json-Schema-to-Zod

| Flag | Shorthand | Function |
| ---------- | --------- | ---------------------------------------------------------------------------------------------- |
| `--input` | `-i` | JSON or a source file path. Required if no data is piped. |
| `--output` | `-t` | A file path to write to. If not supplied stdout will be used. |
| `--name` | `-n` | The name of the schema in the output |
| `--depth` | `-d` | Maximum depth of recursion in schema before falling back to `z.any()`. Defaults to 0. |
| `--module` | `-m` | Module syntax; `esm`, `cjs` or none. Defaults to `esm` in the CLI and `none` programmaticly. |
| `--type` | `-t` | Export a named type along with the schema. Requires `name` to be set and `module` to be `esm`. |
| Flag | Shorthand | Function |
| ------------ | --------- | ---------------------------------------------------------------------------------------------- |
| `--input` | `-i` | JSON or a source file path. Required if no data is piped. |
| `--output` | `-t` | A file path to write to. If not supplied stdout will be used. |
| `--name` | `-n` | The name of the schema in the output |
| `--depth` | `-d` | Maximum depth of recursion in schema before falling back to `z.any()`. Defaults to 0. |
| `--module` | `-m` | Module syntax; `esm`, `cjs` or none. Defaults to `esm` in the CLI and `none` programmaticly. |
| `--type` | `-t` | Export a named type along with the schema. Requires `name` to be set and `module` to be `esm`. |
| `--noImport` | `-ni` | Removes the `import { z } from 'zod';` or equivalent from the output. |

@@ -48,0 +49,0 @@ ### Programmatic

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