form-auto-content is a utility library designed to simplify the creation of HTTP request payloads for web applications, intelligently determining the correct `Content-Type` header and payload format. It automatically switches between `application/x-www-form-urlencoded` and `multipart/form-data` based on the input data: if JavaScript `Stream` objects or `Buffer` instances are present within the input, it defaults to `multipart/form-data` for handling file uploads; otherwise, it constructs a standard `x-www-form-urlencoded` string. The current stable version is 3.2.1, indicating active development with a release cadence that includes minor and patch updates for new features, dependency management, and bug fixes, typically released as needed rather than on a fixed schedule. A key differentiator is its robust auto-sensing capability, allowing developers to pass a single JavaScript object without explicitly specifying the `enctype`. It gracefully handles complex data structures, including nested arrays, and supports advanced file options like custom filenames and content types for `multipart` fields. This makes it particularly useful for interacting with HTTP servers, especially within Node.js environments for server-side forms or API client libraries, and it integrates well with frameworks like Fastify and testing utilities such as `light-my-request`. The library also provides an API to customize the output field names for the generated payload stream and headers object.
npm install form-auto-contentVerified import paths — ran on the pinned version, not inferred.
Demonstrates how `form-auto-content` automatically handles `x-www-form-urlencoded` and `multipart/form-data` payloads, including file streams, buffers, arrays, and custom output field names.
Upgrade your Node.js environment to version 14.0.0 or higher. For older environments, use `form-auto-content@2.x`.
Thoroughly test your application when migrating from v2.x to v3.x. Refer to the GitHub changelog for specific dependency updates that might indirectly affect behavior.
Append `as const` to your options object, e.g., `{ payload: 'body', headers: 'head' } as const`.For ESM, use `import formAutoContent from 'form-auto-content';`. For CommonJS, use `const formAutoContent = require('form-auto-content');`.If custom keys were provided in the options, access them (e.g., `myForm.body`). Ensure the options object is declared with `as const` for accurate type inference: `const options = { payload: 'body', headers: 'head' } as const;`.No dependency data recorded yet.