{"id":15657373,"url":"https://github.com/eomm/form-auto-content","last_synced_at":"2025-04-09T12:06:13.663Z","repository":{"id":39979320,"uuid":"260643933","full_name":"Eomm/form-auto-content","owner":"Eomm","description":"Build a form without headache ","archived":false,"fork":false,"pushed_at":"2025-01-06T23:37:35.000Z","size":41,"stargazers_count":23,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T11:05:36.269Z","etag":null,"topics":["form","hacktoberfest","multipart-formdata","upload","x-www-form-urlencoded"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Eomm.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},"funding":{"github":"Eomm"}},"created_at":"2020-05-02T08:21:43.000Z","updated_at":"2024-10-01T23:47:16.000Z","dependencies_parsed_at":"2023-12-19T02:39:33.012Z","dependency_job_id":"b2744e72-cfaf-4a58-a799-e8d26dede38d","html_url":"https://github.com/Eomm/form-auto-content","commit_stats":{"total_commits":38,"total_committers":7,"mean_commits":5.428571428571429,"dds":0.4736842105263158,"last_synced_commit":"bd1f98a20c0f2522df9ef72cbd1eaea453d0670b"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Fform-auto-content","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Fform-auto-content/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Fform-auto-content/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Eomm%2Fform-auto-content/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Eomm","download_url":"https://codeload.github.com/Eomm/form-auto-content/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"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","hacktoberfest","multipart-formdata","upload","x-www-form-urlencoded"],"created_at":"2024-10-03T13:06:30.116Z","updated_at":"2025-04-09T12:06:13.640Z","avatar_url":"https://github.com/Eomm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/Eomm"],"categories":[],"sub_categories":[],"readme":"# form-auto-content\n\n[![Build Status](https://github.com/Eomm/form-auto-content/workflows/ci/badge.svg)](https://github.com/Eomm/form-auto-content/actions)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n\nBuild a form payload without caring if it should be `application/x-www-form-urlencoded` or `multipart/form-data`.\nIt works with [`Fastify`](https://github.com/fastify/fastify/) and [`light-my-request`](https://github.com/fastify/light-my-request/) too!\n\n## Install\n\n```\nnpm install form-auto-content\n```\n\n## Usage\n\nThis module will transform your JSON to a payload ready to submit to an HTTP server!\nThe autosense feature will check if there is a `stream` or a `buffer` as input and it will act accordingly returning a `multipart/form-data` stream; otherwise it will create a `x-www-form-urlencoded` string.\n\nThe module return a JSON like this:\n\n```js\n{\n  payload: Stream, // the data Stream\n  headers: {} // a JSON with the `content-type` field set\n}\n```\n\n### `x-www-form-urlencoded`\n\n```js\nconst formAutoContent = require('form-auto-content')\n\nconst myForm = formAutoContent({\n  field1: 'value1',\n  field2: ['value2', 'value2.2'] // array are supported too!!\n})\n\nmyForm.payload // Stream of the string in application/x-www-form-urlencoded format\nmyForm.headers // JSON with the `content-type` field set\n```\n\n### `multipart/form-data`\n\n```js\nconst formAutoContent = require('form-auto-content')\n\nconst myForm = formAutoContent({\n  field1: 'value1',\n  field2: ['value2', 'value2.2'], // array are supported too!!\n  myFile: fs.createReadStream('the-file.xml'),\n  multipleFiles: [fs.createReadStream('file1.xml'), fs.createReadStream('file2.xml')],\n  wowBuffer: Buffer.from('a long string'),\n\n  // the file options are supported too:\n  myRenamedFile: {\n    value: fs.createReadStream('./foo.md'),\n    options: {\n      filename: 'bar.md',\n      contentType: 'text/markdown'\n    }\n  },\n  // also in arrays!\n  renamedArray: [\n    {\n      value: fs.createReadStream('./one.json'),\n      options: { filename: 'foo.json' }\n    },\n    {\n      value: fs.createReadStream('./two.json'),\n      options: { filename: 'bar.json' }\n    }\n  ]\n})\n\nmyForm.payload // Stream in multipart/form-data format\nmyForm.headers // JSON with the `content-type` field set to multipart/form-data\n```\n\n## Options\n\nTo customize the output field names, add an extra option object with the `payload` and `headers` string!\n\n```js\nconst formAutoContent = require('form-auto-content')\n\nconst option = { payload: 'body', headers: 'head' }\nconst myCustomForm = formAutoContent({\n  field1: 'value1',\n  field2: ['value2', 'value2.2'] // array are supported too!!\n}, option)\n\nmyForm.body // Stream of the string in application/x-www-form-urlencoded format\nmyForm.head // JSON with the `content-type` field set\n```\n\n## Typescript\n\nThis module ships with a handwritten TypeScript declaration file for TS support. The declaration exports a single function.\n\n```ts\nimport formAutoContent from 'form-auto-content';\n```\n\nWhen an options object is provided, the result types will be accurately inferred:\n\n```ts\nimport formAutoContent from 'form-auto-content';\n\nconst option = {\n  payload: 'body',\n  headers: 'head',\n  forceMultiPart: true,\n} as const;\n\nconst myCustomForm = formAutoContent({\n  field1: 'value1',\n  field2: ['value2']\n}, option);\n\nmyCustomForm.body // ok\nmyCustomForm.head // ok\n\nmyCustomForm.payload // Typescript error: property 'payload' does not exists in type...\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feomm%2Fform-auto-content","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feomm%2Fform-auto-content","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feomm%2Fform-auto-content/lists"}