{"id":15315806,"url":"https://github.com/wobsoriano/h3-formidable","last_synced_at":"2025-04-13T12:05:23.994Z","repository":{"id":62478034,"uuid":"560716512","full_name":"wobsoriano/h3-formidable","owner":"wobsoriano","description":"File upload parsing utility for h3 and Nuxt.","archived":false,"fork":false,"pushed_at":"2023-09-28T21:56:49.000Z","size":133,"stargazers_count":62,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-10T13:44:40.440Z","etag":null,"topics":["form","h3","multipart","nuxt","upload"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wobsoriano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-11-02T05:17:40.000Z","updated_at":"2025-02-09T14:16:45.000Z","dependencies_parsed_at":"2023-09-28T23:09:44.476Z","dependency_job_id":null,"html_url":"https://github.com/wobsoriano/h3-formidable","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"08d41c29d6fbb5d33b939da95311c96fd9e17c33"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fh3-formidable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fh3-formidable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fh3-formidable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fh3-formidable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wobsoriano","download_url":"https://codeload.github.com/wobsoriano/h3-formidable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245773172,"owners_count":20669719,"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":["form","h3","multipart","nuxt","upload"],"created_at":"2024-10-01T08:52:16.264Z","updated_at":"2025-03-29T08:31:31.213Z","avatar_url":"https://github.com/wobsoriano.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# h3-formidable\n\n[![npm (tag)](https://img.shields.io/npm/v/h3-formidable?style=flat\u0026colorA=000000\u0026colorB=000000)](https://www.npmjs.com/package/h3-formidable) ![NPM](https://img.shields.io/npm/l/h3-formidable?style=flat\u0026colorA=000000\u0026colorB=000000)\n\nFile upload parsing utility for h3 and Nuxt using [formidable](https://github.com/node-formidable/formidable).\n\nDemo - https://stackblitz.com/edit/nuxt-starter-ykuwmn\n\n## Install\n\n```bash\nnpm install h3-formidable\n```\n\n## Usage\n\nThis example shows Nuxt usage but you can use it with any h3 app.\n\n1. Create a server middleware\n\n```ts\nimport { createFileParserMiddleware } from 'h3-formidable'\n\nexport default createFileParserMiddleware({\n  // formidable options\n})\n```\n\n2. Access files in your api route\n\n```ts\nexport default eventHandler(async (event) =\u003e {\n  const { files } = event.context.formidable\n})\n```\n\nor you can ditch server middleware and parse files per api route...\n\n```ts\nimport { readFiles } from 'h3-formidable'\n\nexport default eventHandler(async (event) =\u003e {\n  const { fields, files, form } = await readFiles(event, {\n    // formidable options\n    // https://github.com/node-formidable/formidable#options\n  })\n})\n```\n\n## Plugins\n\nIf you have a custom [plugin](https://github.com/node-formidable/formidable#useplugin-plugin), you can use the `getForm` option to access the incoming form and do whatever you want with it.\n\n```ts\nexport default eventHandler(async (event) =\u003e {\n  const { fields, files } = await readFiles(event, {\n    getForm(form) {\n      form.use(() =\u003e {\n        console.log('woohoo, custom plugin')\n      })\n    }\n  })\n})\n```\n\nAnything inside the getForm callback will be executed before the form is parsed.\n\n## Helpers\n\n```ts\nimport { firstValues, readBooleans } from 'h3-formidable/helpers'\n\nexport default eventHandler(async (event) =\u003e {\n  const { fields, files, form } = await readFiles(event)\n\n  // Gets first values of fields\n  const exceptions = ['thisshouldbeanarray']\n  const fieldsSingle = firstValues(form, fields, exceptions)\n\n  // Converts html form input type=\"checkbox\" \"on\" to boolean\n  const expectedBooleans = ['checkbox1', 'wantsNewsLetter', 'hasACar']\n  const fieldsWithBooleans = readBooleans(fieldsSingle, expectedBooleans)\n})\n```\n\n## TypeScript Shim\n\n```ts\ndeclare module 'h3' {\n  import type { Result } from 'h3-formidable'\n\n  interface H3EventContext {\n    formidable: Result\n  }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwobsoriano%2Fh3-formidable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwobsoriano%2Fh3-formidable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwobsoriano%2Fh3-formidable/lists"}