-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat(laconia-config): Parse integers and floats from LACONIA_CONFIG_ env variables #543
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything is ok, thanks 👍
Only missed tests for NaN, to makes it clear what we should expect when string isn't float/integer.
Yeah I was thinking how we handle that. Should we throw an error if either is NaN, or just return NaN? |
NaN is good enough 😉 |
I kind of prefer throwing, over returning NaN. As a user, I'll discover my configuration error faster if Laconia is throwing that error for me, instead of me discovering that I'm passing NaN into our app code. I take the error as a configuration issue as, if I configure Thoughts? |
Ah yeah if we're throwing in another one with an unexpected value, I'd say we throw here too, or at the very least return |
Some days ago I was thinking that if null invention was billion dollar. JavaScript has trillion dollars mistake (null, undefined and NaN) :-) NaN: user could write defensive code; Both ok, stay with exception for consistency. |
Sounds good. One more case I thought of, what should happen if I pass |
|
I updated the tests for We could probably combine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt('1avocado', 10) === 1
🤯
Super optional, but maybe it's worth adding a unit test to show this behaviour (Or maybe I'm just not used to it), or document that we're just using parseInt
so we'll be able to parse 1avocado
Ha yeah I was thinking about that too when mixing numbers and letters/other chars. We could do something like:
Otherwise I'd say just call it out in the docs. Any preference? |
Maybe just comment in the docs 😅 |
@geoffdutton It seems like @hugosenari is genuinely waiting for this one, haha. I prefer to throw an error as you have made it look super simple to implement, but I'm happy to merge and release to make it available with this one! Let me know! |
…sed as floats or ints
I implemented those checks as well, but I'll still call it out int he docs. Should be good to go. |
Current regex fail for negative inputs? Any reason to not use if (isNaN(parsedVal) || val.macth(floatRegex)) edit: found this related next JS iteration has |
Good call on the negative numbers and using I think for now we ignore the
I will update the documentation to reflect when errors are thrown now. Do one of you want to merge the PR per the "don't merge your own PRs" guideline? |
This adds an integer converter and float converter when parking
LACONIA_CONFIG_
environment variables (#542).Note: There was a
.forEach
with an async callback in the acceptance test that I changed to afor..of
loop in order to properly await the promises.