antfu / utils

Collection of common JavaScript / TypeScript utils
MIT License
791 stars 60 forks source link

feat: `toBoolean` convert util #40

Closed blasdfaa closed 11 months ago

blasdfaa commented 11 months ago

Description

Converts any value to a boolean value.

Linked Issues

N/A

Additional context

N/A

antfu commented 11 months ago

I am not so sure about it. I think the usage is a bit unclear and you don't always want to convert false to false. Without that conversion, I think a Boolean(value) would already do the thing.

blasdfaa commented 11 months ago

I am not so sure about it. I think the usage is a bit unclear and you don't always want to convert false to false. Without that conversion, I think a Boolean(value) would already do the thing.

Such a function could be useful when converting boolean strings. For example, query parameters (foo=true&bar=false)

antfu commented 11 months ago

Yes, I knew. And also for env value parsing, I suppose. My point is that they are specific use cases. In general, most of the time, you don't want this convention. Even if you two, it's just a few line in the code base to create a local util. I think I am not confident to have it in this project. Thanks for bringing this up.