New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Default Value for toNumber("problem", 0) #5826
Comments
@jdalton I would like to take this up if this change is needed or if it's not done already. |
#5852 - PR |
I left this comment on the PR, but I think an options object is probably a better API. |
Makes sense, let me make this change |
It seems like this feature would typically be used to return 0 instead of |
Not necessarily. Any number could be set as a default for a missing/wrong value in a config file. By example a upper limit for a certain amount of money, ... |
That suggests a poorly designed API. A default value is what I would expect when someone provides no value. But this handles situations where invalid information is provided which seems like a footgun/anti-pattern. As always, I'm not a lodash maintainer, but it does seem like this adds complexity to the API for a usage that is typically better handled in the application itself. |
I agree, treating a wrong value like a missing one is very likely to be a bad idea. Maybe was I trying to solve a problem that should not be solved at this level, indeed. |
It would be nice to be allowed to pass an (optional) default value for the conversion function
toNumber()
.Currently, toNumber() returns NaN if the passed value is not a number:
The following would return 0 instead:
This would be very useful when using this function to parse config files.
The text was updated successfully, but these errors were encountered: