{"id":24460914,"url":"https://github.com/marcuwynu23/form-data-generator","last_synced_at":"2025-03-14T09:43:27.016Z","repository":{"id":272463532,"uuid":"889616251","full_name":"marcuwynu23/form-data-generator","owner":"marcuwynu23","description":"FormDataGenerator is a JavaScript class designed to simplify the creation and management of FormData objects, allowing for easy handling of file uploads and chunked data in both Node.js and browser environments.","archived":false,"fork":false,"pushed_at":"2025-01-14T15:17:01.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T03:56:48.298Z","etag":null,"topics":["axios","chunk","form-data"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/marcuwynu23.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-16T19:24:41.000Z","updated_at":"2025-01-14T15:17:05.000Z","dependencies_parsed_at":"2025-01-14T16:44:37.177Z","dependency_job_id":"265b0126-e724-4aee-8b31-977012edf72b","html_url":"https://github.com/marcuwynu23/form-data-generator","commit_stats":null,"previous_names":["marcuwynu23/form-data-generator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuwynu23%2Fform-data-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuwynu23%2Fform-data-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuwynu23%2Fform-data-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcuwynu23%2Fform-data-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcuwynu23","download_url":"https://codeload.github.com/marcuwynu23/form-data-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243558468,"owners_count":20310572,"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":["axios","chunk","form-data"],"created_at":"2025-01-21T04:16:02.377Z","updated_at":"2025-03-14T09:43:26.973Z","avatar_url":"https://github.com/marcuwynu23.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e FormData Generator \u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/stars/marcuwynu23/form-data-generator.svg\" alt=\"Stars Badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/github/forks/marcuwynu23/form-data-generator.svg\" alt=\"Forks Badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/github/issues/marcuwynu23/form-data-generator.svg\" alt=\"Issues Badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/github/license/marcuwynu23/form-data-generator.svg\" alt=\"License Badge\"/\u003e\n\u003c/p\u003e\n\n`FormDataGenerator` is a JavaScript class designed to simplify the creation and management of `FormData` objects, allowing for easy handling of file uploads and chunked data in both Node.js and browser environments.\n\n## Features\n\n- Create and manage `FormData` objects.\n- Set individual items or chunked items for file uploads.\n- Retrieve items as arrays or individual items.\n- Works seamlessly in both Node.js and browser environments.\n\n## Installation\n\n### Node.js\n\nIf you are using Node.js, install the `form-data` package:\n\n```bash\nnpm install form-data\n```\n\n### Browser\n\nIn a browser environment, simply include the script in your HTML file:\n\n```html\n\u003cscript src=\"path/to/FormDataGenerator.js\"\u003e\u003c/script\u003e\n```\n\n\n### Usage\n#### Importing the Class\n\nIn Node.js, you can import the FormDataGenerator class as follows:\n\n```javascript\nconst { FormDataGenerator } = require('./path/to/FormDataGenerator');\n```\n\nIn a browser, you can directly use FormDataGenerator after including the script.\n\n\n\n\n\n#### Creating a FormDataGenerator Instance\n\nYou can create an instance of FormDataGenerator like this:\n\n```javascript\nconst formDataGenerator = new FormDataGenerator(new FormData());\n```\n\n#### Setting Items\n\nYou can set items in the FormData object using the setItem method:\n\n```javascript\nformDataGenerator.setItem('username', 'john_doe');\n```\n\n\n#### Setting Chunked Items\n\nFor file uploads, you can use the setChunkItem method to handle large files in chunks:\n\n```javascript\nconst fileInput = document.getElementById('fileInput');\nconst file = fileInput.files[0];\nconst options = { limit: 5 }; // Set chunk size limit in MB\n\nformDataGenerator.setChunkItem('file', file, options);\n```\n#### Retrieving Items\n\nYou can retrieve individual items or all items:\n\n```javascript\nconst username = formDataGenerator.getItem('username');\nconsole.log(username); // Output: john_doe\n\nconst itemsArray = formDataGenerator.getItemsAsArray();\nconsole.log(itemsArray); // Output: [{ name: 'username', value: 'john_doe' }, ...]\n\nconst items = formDataGenerator.getItems();\nconsole.log(items); \n```\n\n### API\n\n##### `constructor(formData?)`\n\n- **Parameters**: \n  - `formData` (optional): An existing `FormData` object to initialize.\n\n##### `setItem(name, value)`\n\n- **Parameters**:\n  - `name`: The name of the item to set.\n  - `value`: The value to associate with the name.\n\n##### `setChunkItem(name, value, options)`\n\n- **Parameters**:\n  - `name`: The name of the item to set.\n  - `value`: The `File` or buffer object to be chunked.\n  - `options`: An object containing `limit` (in MB) for chunk size.\n\n##### `getItem(name)`\n\n- **Parameters**:\n  - `name`: The name of the item to retrieve.\n- **Returns**: The value associated with the specified name.\n\n##### `getItemsAsArray()`\n\n- **Returns**: An array of all items in the `FormData` object.\n\n##### `getItems()`\n\n- **Returns**: An array of objects containing `name` and `value` pairs for all items.\n\n\n### License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n### Contributing\n\nContributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.\n\n### Acknowledgments\n\n**form-data** for handling form data in Node.js.\n**MDN Web Docs** for documentation on the FormData API.\n\n\n\n### How to Use\n\n1. **Create a new file**: Open your text editor or IDE.\n2. **Copy the content**: Copy the above Markdown content.\n3. **Paste it into the file**: Paste the content into the new file.\n4. **Save the file**: Save the file with the name `README.md`.\n\nThis will create a well-structured README file for your `FormDataGenerator` class. You can adjust any sections as needed to fit your project's specific details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcuwynu23%2Fform-data-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcuwynu23%2Fform-data-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcuwynu23%2Fform-data-generator/lists"}