{"id":18317928,"url":"https://github.com/idiocc/form","last_synced_at":"2025-10-15T09:46:03.644Z","repository":{"id":57128690,"uuid":"195365786","full_name":"idiocc/form","owner":"idiocc","description":"A Node.JS Class To Create Multipart/Form-Data Requests With Files and Fields.","archived":false,"fork":false,"pushed_at":"2019-12-24T09:19:06.000Z","size":87,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-15T12:34:08.130Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.idio.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiocc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-05T07:57:07.000Z","updated_at":"2019-12-24T09:19:08.000Z","dependencies_parsed_at":"2022-08-31T17:22:25.028Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/form","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054218,"owners_count":21039951,"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":"2024-11-05T18:07:54.528Z","updated_at":"2025-10-15T09:45:58.614Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @multipart/form\n\n[![npm version](https://badge.fury.io/js/%40multipart%2Fform.svg)](https://www.npmjs.com/package/@multipart/form)\n\n`@multipart/form` is A _Node.JS_ Class To Create Multipart/Form-Data Requests With Files and Fields.\n\n```sh\nyarn add @multipart/form\nnpm install @multipart/form\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`class Form`](#class-form)\n  * [`Form`](#type-form)\n  * [`FormConfig`](#type-formconfig)\n  * [`AddFileOptions`](#type-addfileoptions)\n- [Copyright \u0026 License](#copyright--license)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/0.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its default class:\n\n```js\nimport Form from '@multipart/form'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/1.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## `class Form`\n\nThe form class maintains an internal buffer with data that can be sent in a `multipart/form-data` request. It can append fields and files, and when a file path is given, it will be read from the file system and its contents will be added to the form data.\n\n__\u003ca name=\"type-form\"\u003e`Form`\u003c/a\u003e__: Accumulates data in fields and returns the complete body.\n\u003ctable\u003e\n \u003cthead\u003e\u003ctr\u003e\n  \u003cth\u003eName\u003c/th\u003e\n  \u003cth\u003eType \u0026amp; Description\u003c/th\u003e\n \u003c/tr\u003e\u003c/thead\u003e\n \u003ctr\u003e\n  \u003ctd rowSpan=\"3\" align=\"center\"\u003e\u003cins\u003econstructor\u003c/ins\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003enew (config: \u003ca href=\"#type-formconfig\" title=\"Options for the constructor.\"\u003e!FormConfig\u003c/a\u003e) =\u003e \u003ca href=\"#type-form\" title=\"Accumulates data in fields and returns the complete body.\"\u003eForm\u003c/a\u003e\u003c/em\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n   Creates a new form instance that maintains a buffer of key-value pairs and files separated by a boundary.\n  \u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd rowSpan=\"3\" align=\"center\"\u003e\u003cins\u003ebuffer\u003c/ins\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003e!Buffer\u003c/em\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n   The data to send.\n  \u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd rowSpan=\"3\" align=\"center\"\u003e\u003cins\u003edata\u003c/ins\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003estring\u003c/em\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n   The data to send as utf-8 string. Concatenates the buffer data with \u003ccode\u003e\\r\\n\u003c/code\u003e and adds the final \u003ccode\u003e--{boundary}--\u003c/code\u003e to the returned string.\n  \u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd rowSpan=\"3\" align=\"center\"\u003e\u003cins\u003eaddFile\u003c/ins\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003e(path: string, name: string, options?: \u003ca href=\"#type-addfileoptions\" title=\"Options for adding files.\"\u003e!AddFileOptions\u003c/a\u003e) =\u003e void\u003c/em\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n   Reads and adds the file to the request buffer.\n  \u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd rowSpan=\"3\" align=\"center\"\u003e\u003cins\u003eaddSection\u003c/ins\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003e(key: string, value: (!Buffer | string)) =\u003e void\u003c/em\u003e\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\n   Adds a key-value pair to the form.\n  \u003c/td\u003e\n \u003c/tr\u003e\n\u003c/table\u003e\n\n__\u003ca name=\"type-formconfig\"\u003e`FormConfig`\u003c/a\u003e__: Options for the constructor.\n\n\n|   Name   |      Type       |                Description                |                      Default                       |\n| -------- | --------------- | ----------------------------------------- | -------------------------------------------------- |\n| boundary | \u003cem\u003estring\u003c/em\u003e | The hard-coded boundary for the requests. | `u2KxIV5yF1y+xUspOQCCZopaVgeV6Jxihv35XQJmuTx8X3sh` |\n\n\n__\u003ca name=\"type-addfileoptions\"\u003e`AddFileOptions`\u003c/a\u003e__: Options for adding files.\n\n\n|   Name   |       Type       |                                                   Description                                                   |          Default           |\n| -------- | ---------------- | --------------------------------------------------------------------------------------------------------------- | -------------------------- |\n| type     | \u003cem\u003estring\u003c/em\u003e  | The _Content-Type_ description.                                                                                 | `application/octet-stream` |\n| noCache  | \u003cem\u003eboolean\u003c/em\u003e | Whether to not cache read files.                                                                                | `false`                    |\n| filename | \u003cem\u003estring\u003c/em\u003e  | The `filename` property for _Content-Disposition_ description. By default, will be same as the `path` argument. | -                          |\n\n```js\nimport Form from '@multipart/form'\n\n(async () =\u003e {\n  const form = new Form()\n  await form.addFile(`test/fixture/test.txt`, 'file')\n  form.addSection('hello', 'world')\n  console.log(form.data)\n})()\n```\n```http\n--u2KxIV5yF1y+xUspOQCCZopaVgeV6Jxihv35XQJmuTx8X3sh\nContent-Disposition: form-data; name=\"file\"; filename=\"test/fixture/test.txt\"\nContent-Type: application/octet-stream\n\na test file\n\n--u2KxIV5yF1y+xUspOQCCZopaVgeV6Jxihv35XQJmuTx8X3sh\nContent-Disposition: form-data; name=\"hello\"\n\nworld\n--u2KxIV5yF1y+xUspOQCCZopaVgeV6Jxihv35XQJmuTx8X3sh--\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/2.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## Copyright \u0026 License\n\nGNU Affero General Public License v3.0\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://artd.eco\"\u003e\n        \u003cimg width=\"100\" src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\"\n          alt=\"Art Deco\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e© \u003ca href=\"https://artd.eco\"\u003eArt Deco\u003c/a\u003e for \u003ca href=\"https://idio.cc\"\u003eIdio\u003c/a\u003e 2019\u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://idio.cc\"\u003e\n        \u003cimg src=\"https://avatars3.githubusercontent.com/u/40834161?s=100\" width=\"100\" alt=\"Idio\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\"\u003e\n        \u003cimg width=\"100\" src=\"https://raw.githubusercontent.com/idiocc/cookies/master/wiki/arch4.jpg\"\n          alt=\"Tech Nation Visa\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003ca href=\"https://www.technation.sucks\"\u003eTech Nation Visa Sucks\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/-1.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Fform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fform/lists"}