class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

Enhance boolean conversion logic for strings and numeric values

Open GFoniX opened this issue 1 year ago • 3 comments

Description

This update improves the boolean conversion logic when handling string values in the type mapping. The changes include:

  • Converting strings representing numbers (e.g., '1', '0') to booleans.
  • Handling specific string values like 'true' and 'false' to map them to their correct boolean counterparts.

This ensures more consistent and accurate conversions when dealing with strings that are either numeric or represent boolean values.

Checklist

  • [x] the pull request title describes what this PR does (not a vague title like Update index.md)
  • [x] the pull request targets the default branch of the repository (develop)
  • [x] the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • [x] tests are added for the changes I made (if any source code was modified)
  • [ ] documentation added or updated
  • [x] I have run the project locally and verified that there are no errors

Fixes

fixes #676, fixes #626

This fix ensures that query parameters sent as strings, which are common in NestJS, are correctly converted to booleans when using class-transformer. It prevents incorrect boolean conversions that previously resulted in all such values being interpreted as true. For exemple have '1', '0', 'true', 'false' result to having true.

GFoniX avatar Oct 24 '24 09:10 GFoniX

Hi @typestack,
I would like to know if there's anything missing for my PR to be approved.
Thank you!

GFoniX avatar Nov 21 '24 10:11 GFoniX

Very interesting, might be very useful :+1:

jeremycalvo avatar Dec 17 '24 09:12 jeremycalvo

Is there something that can block my Pr ?

GFoniX avatar Feb 06 '25 10:02 GFoniX