Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@conform-to/zod
Advanced tools
This resolves zod schema to a conform schema:
import { useFieldset } from '@conform-to/react';
import { resolve } from '@conform-to/zod';
import { z } from 'zod';
// Define the schema with zod
const schema = z.object({
email: z.string(),
password: z.string(),
});
// When used with `@conform-to/react`:
function RandomForm() {
const [setupFieldset, { email, password }] = useFieldset(resolve(schema));
// ...
}
The parse
function could be used to parse the FormData on client side:
const schema = z.object({
// Define the schema with zod
});
form.addEventListener('submit', (e) => {
e.preventDefault();
// Read the FormData from the from
const formData = new FormData(e.target);
// Parse the data against the zod schema
const result = parse(formData, schema);
console.log(result.state);
// It could be accepted / rejected / processed
console.log(result.value);
// Parsed value (if accepted)
// or Fieldset data in schema structure (if not)
console.log(result.error);
// Fieldset error in schema structure (if rejected)
});
Or parse the request payload on server side (e.g. Remix):
import { parse } from '@conform-to/zod';
import { z } from 'zod';
const schema = z.object({
// Define the schema with zod
});
export let action = async ({ request }) => {
const formData = await request.formData();
const result = parse(formData, schema);
// Depends on the usecase, you can also do this:
// const url = new URL(request.url)
// const result = parse(url.searchParams, schema)
// Return the current result if not accepted
if (result.state !== 'accepted') {
return json(result);
}
// Do something else
};
export default function SomeRoute() {
const result = useActionData();
// You can then use result.value / result.error
// to populate inital value of each fields and
// its corresponding error
}
FAQs
Conform helpers for integrating with Zod
The npm package @conform-to/zod receives a total of 28,977 weekly downloads. As such, @conform-to/zod popularity was classified as popular.
We found that @conform-to/zod demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.