{"id":27624211,"url":"https://github.com/probablykasper/niceform","last_synced_at":"2025-07-08T18:03:31.278Z","repository":{"id":275260695,"uuid":"925576291","full_name":"probablykasper/niceform","owner":"probablykasper","description":"Convenient form validation and typing for SvelteKit","archived":false,"fork":false,"pushed_at":"2025-02-02T13:01:00.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T21:44:40.456Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/probablykasper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-01T07:37:31.000Z","updated_at":"2025-02-02T13:01:04.000Z","dependencies_parsed_at":"2025-02-01T08:37:07.431Z","dependency_job_id":null,"html_url":"https://github.com/probablykasper/niceform","commit_stats":null,"previous_names":["probablykasper/niceform"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablykasper%2Fniceform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablykasper%2Fniceform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablykasper%2Fniceform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/probablykasper%2Fniceform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/probablykasper","download_url":"https://codeload.github.com/probablykasper/niceform/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250422383,"owners_count":21427937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-23T11:22:19.856Z","updated_at":"2025-04-23T11:22:20.435Z","avatar_url":"https://github.com/probablykasper.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# niceform\nConvenient form validation and typing for SvelteKit. Based on Superforms and Zod.\n\nMight turn this into an actual package later\n\nFeatures\n- `name` attribute typing\n- Multiple forms\n- i18n\n- Snapshots\n\n### Example `+page.server.ts`\n```ts\nimport { z } from 'zod'\nimport { nice_form } from '$lib/niceform'\n\nconst schema = z.object({\n\tname: z.string(),\n})\n\nexport const actions = {\n\tasync default(event) {\n\t\tconst form = await nice_form.zod(schema, event)\n\t\tif (!form.valid) {\n\t\t\treturn form.fail(400)\n\t\t}\n\t\tif (form.data.name === 'Hi') {\n\t\t\treturn form.set_error('name', 'You are a failure')\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t}\n\t},\n}\n```\n\n### Example Input wrapper component\n\nIncludes type-safe `name` attribute, automatic error messages and label with automatic ID\n\n\u003cimg width=\"644\" alt=\"image\" src=\"https://github.com/user-attachments/assets/f1013bc2-5e61-4a50-b8c4-f3dafa54d3c3\" /\u003e\n\n\n```svelte\n\u003cscript lang=\"ts\" generics=\"F extends PartialNiceForm\"\u003e\n\timport { sequential_num, type AddFormProps, type PartialNiceForm } from './niceform'\n\timport type { HTMLInputAttributes } from 'svelte/elements'\n\n\tlet {\n\t\tform,\n\t\tlabel,\n\t\tvalue = $bindable(),\n\t\t...props\n\t}: AddFormProps\u003cHTMLInputAttributes, F\u003e = $props()\n\n\tlet errors = $derived(form?.errors ?? {})\n\n\tconst id = 'input-' + sequential_num()\n\u003c/script\u003e\n\n\u003cdiv\u003e\n\t{#if label}\n\t\t\u003clabel class=\"text-label mb-0.5 block text-sm\" for={props.id ?? id}\u003e{label}\u003c/label\u003e\n\t{/if}\n\t\u003cinput id={label ? id : undefined} bind:value {...props} class={['input', props['class']]} /\u003e\n\t{#if props.name \u0026\u0026 errors[props.name]}\n\t\t\u003cspan class=\"text-red-500\"\u003e{errors[props.name]}\u003c/span\u003e\n\t{/if}\n\u003c/div\u003e\n\n```\n\n### i18n example\n```ts\nimport { z } from 'zod'\nimport * as m from '$lib/paraglide/messages'\nimport { set_error_map } from './niceform'\n\nexport const form_errors = set_error_map({\n\tinvalid_email: m.invalid_email,\n})\n\nexport const email_schema = z.string().email(form_errors.invalid_email).max(100)\n```\n\n### Snapshots\n\nMight change this API\n\n```ts\n\u003cscript lang=\"ts\"\u003e\nimport { enhance } from '$app/forms'\nimport { auto_snapshot } from '$lib/niceform'\n\nconst snapshotter = auto_snapshot()\nexport const snapshot = auto_snapshot()\n\u003c/script\u003e\n\n\u003cform method=\"post\" use:enhance use:snapshotter.container\u003e\n\t\u003cInput {form} type=\"text\" data-snapshot /\u003e\n\u003c/form\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobablykasper%2Fniceform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprobablykasper%2Fniceform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprobablykasper%2Fniceform/lists"}