{"id":15828098,"url":"https://github.com/manchenkoff/object-form-encoder","last_synced_at":"2025-04-01T10:44:17.546Z","repository":{"id":198968645,"uuid":"701901421","full_name":"manchenkoff/object-form-encoder","owner":"manchenkoff","description":"Utility to normalize and convert objects into FormData","archived":false,"fork":false,"pushed_at":"2023-10-21T10:07:12.000Z","size":930,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-12T10:44:40.822Z","etag":null,"topics":["converter","formdata","json","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/object-form-encoder","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/manchenkoff.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":"2023-10-07T22:46:54.000Z","updated_at":"2024-02-06T12:52:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"a825ca7b-4da8-4834-b11f-9676ce945fd6","html_url":"https://github.com/manchenkoff/object-form-encoder","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"b2060e638e97a23de6c3224507fb00fa99d3a124"},"previous_names":["manchenkoff/object-form-encoder"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manchenkoff%2Fobject-form-encoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manchenkoff%2Fobject-form-encoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manchenkoff%2Fobject-form-encoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manchenkoff%2Fobject-form-encoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manchenkoff","download_url":"https://codeload.github.com/manchenkoff/object-form-encoder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246628400,"owners_count":20808105,"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":["converter","formdata","json","typescript"],"created_at":"2024-10-05T10:21:39.731Z","updated_at":"2025-04-01T10:44:17.531Z","avatar_url":"https://github.com/manchenkoff.png","language":"TypeScript","readme":"# Object Form Encoder\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![License][license-src]][license-href]\n[![Nuxt][nuxt-src]][nuxt-href]\n\nThis package provides a simple way to convert any object to a FormData instance to send it to remote server.\n\n## Features\n\n-   Convert any object to FormData instance\n-   Converts complex objects to JSON strings\n-   Normalizes Dates to ISO strings\n-   Assigns arrays with `key[]` syntax\n\n## Installation\n\n1. Add `object-form-encoder` dependency to your project\n\n```bash\n# Using pnpm\npnpm add -D object-form-encoder\n\n# Using yarn\nyarn add --dev object-form-encoder\n\n# Using npm\nnpm install --save-dev object-form-encoder\n```\n\nThat's it! You can now use this package in your app ✨\n\n## Usage\n\nLet's imagine that you have this object in your application code:\n\n```typescript\nconst payload = {\n    name: 'John',\n    roles: ['user', 'admin'],\n    is_active: true,\n    has_children: false,\n    age: 30,\n    address: {\n        street: 'Street name',\n        city: 'City name',\n    },\n    created_at: new Date('2020-01-01'),\n    avatar: new File(['foo'], 'foo.txt'), // e.g. from \u003cinput type=\"file\" /\u003e\n    uploads: new FileList([...]), // e.g. from \u003cinput type=\"file\" multiple /\u003e\n};\n```\n\nAnd you need to send it to the server as `multipart/form-data` request. You can do it with this package:\n\n```typescript\nimport { objectToFormData } from 'object-form-encoder';\n\nconst formData = objectToFormData(payload);\n```\n\nNow you are free to send this `formData` to the remote API.\n\n### Normalization\n\nSince some types should be normalized before appending to the `FormData` instance, this package contains a list of normalizers for such types:\n\n-   `FileList` - appends each file to the same key with `key[]` syntax\n-   `Array` - appends each item to the same key with `key[]` syntax\n-   `File` - appends as is\n-   `Date` - normalizes to ISO string\n-   `Boolean` - converts to `1` or `0` string\n-   `Object` - converts to JSON string\n-   `Scalar` - appends as is (any type that is not `object`)\n\nEach normalizer applies only once and the order of normalizers is the same as in the list above.\n\n## Development\n\n```bash\n# Install dependencies\nyarn install\n\n# Build package\nyarn build\n\n# Run Prettier\nyarn fmt\n\n# Run ESLint\nyarn lint\n\n# Run Vitest\nyarn test\n\n# Release new version\nyarn release\n```\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/object-form-encoder/latest.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n[npm-version-href]: https://npmjs.com/package/object-form-encoder\n[npm-downloads-src]: https://img.shields.io/npm/dm/object-form-encoder.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n[npm-downloads-href]: https://npmjs.com/package/object-form-encoder\n[license-src]: https://img.shields.io/npm/l/object-form-encoder.svg?style=flat\u0026colorA=18181B\u0026colorB=28CF8D\n[license-href]: https://npmjs.com/package/object-form-encoder\n[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js\n[nuxt-href]: https://nuxt.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanchenkoff%2Fobject-form-encoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanchenkoff%2Fobject-form-encoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanchenkoff%2Fobject-form-encoder/lists"}