fabian-hiller / decode-formdata

Decodes complex FormData into a JavaScript object
MIT License
241 stars 7 forks source link

Boolean strings #1

Closed sillvva closed 1 year ago

sillvva commented 1 year ago

One issue I ran into was that the decode function doesn't parse "true" or "false" strings to their corresponding boolean values. Both just result in true. To get false, you need to exclude the field from the form data altogether.

I think this could be an area for improvement.

fabian-hiller commented 1 year ago

Great idea. I will think about it. Feel free to create a PR if you have time.

fabian-hiller commented 1 year ago

Here is the code located: https://github.com/fabian-hiller/decode-formdata/blob/main/src/utils/getFieldValue/getFieldValue.ts#L19-L21

fabian-hiller commented 1 year ago

Maybe this is the solution:

if (info?.booleans?.includes(templateName)) {
  return value !== 'false' && value !== '0';
}
sillvva commented 1 year ago

I haven't taken the time to study the code yet, but that looks good to me.

fabian-hiller commented 1 year ago

Will add it later