node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7.05k stars 682 forks source link

Url search params and remove multiple #730

Closed GrosSacASac closed 3 years ago

GrosSacASac commented 3 years ago

remove multiples remove unused qs and querystring dependency

files and fields are always arrays to avoid type errors use modern URLSearchParams https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams internally

GrosSacASac commented 3 years ago

fixes https://github.com/node-formidable/formidable/issues/634, https://github.com/node-formidable/formidable/issues/485, https://github.com/node-formidable/formidable/issues/400, https://github.com/node-formidable/formidable/issues/292

tunnckoCore commented 3 years ago

I will review it soon.

GrosSacASac commented 3 years ago

An utility to force get singular values

const firstValuesOfFields = fields => {
    return Object.fromEntries(Object.entries(fields).map(([key, value]) => {
        return [key, value[0]];    
    }));
};

// ...

form.parse(request, async (err, fieldsM /*files*/) => {
        const fields = firstValuesOfFields(fieldsM);