-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor: toBoolean does more; narrower predicates #125
Conversation
a2e1870
to
7b8e49a
Compare
I don't see them in here, were the benchmarks updated for these changes as well? |
I was waiting to update the bench tests till after we agree on a general direction; no need to benchmark something that isn't going to move forward. |
Feels like maybe we also want something that is |
The converter
I don't think it is a good idea to include all of the specific cases - yes + true + no or no + off + false - into a single call. My thought is that in cases where the comparison is for "on" or "off" it should not also match "yes" or "no". I am only able to draw from experience and conjecture without knowing some of the specific scenarios we run into. |
I decided to sever the relationship between First thought, for Second, for the predicates, |
*/ | ||
export const isFalse = (val: unknown) => test(falseValues, val); | ||
export const isFalse = (val: unknown) => test(listFalse, val); |
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.
I do like the separation of the three checks, although I think in our current use cases of this predicate we want to check against all of these. Would it perhaps make sense to do a isFalsey()
function that checks isFalse() || isOff() || isNo()
so we can do just a single check in userland (for general use cases)
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.
Is that a use case? Is a value likely to be "Off" or "No"?
In my experience I would expect a value to be either: "On" or "Off" or true
or false
but nothing else and another value might be of a different variant.
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.
It is a use case for us on a project now, yeah, as we have seen both variations due to bad data and would like a single function to accommodate all
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.
I've added the two additional functions - isAnyFalsy
and isAnyTruthy
- named that way to "distance" them from isFalse
and isTrue
. I don't have a strong feeling about this naming so if people hate it I can change it.
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.
i think I prefer isFalsy
/isTruthy
, but I understand the motivation behind the current naming and am not opposed to leaving it
@kalisjoshua will need a changeset, otherwise LGTM |
55ed77a
to
662b58c
Compare
the toBoolean function centralizes the logic for coercing a value and allows the predicate functions to be more specific in what they validate rather than them simply being alais names to broad validation. closes #122
662b58c
to
114c924
Compare
Changeset added. |
*/ | ||
export const isFalse = (val: unknown) => test(falseValues, val); | ||
export const isFalse = (val: unknown) => test(listFalse, val); |
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.
i think I prefer isFalsy
/isTruthy
, but I understand the motivation behind the current naming and am not opposed to leaving it
${isOff} | ${[...falsy, ' off', 'OFF ']} | ${[...truthy, 'on', 'string with off', 'of']} | ||
${isOn} | ${[...truthy, ' on', 'ON ']} | ${[...falsy, 'of', 'string with on', 'o']} | ||
${isTrue} | ${[...truthy, ' true']} | ${[...falsy, 'any string', {}, [], /abc/]} | ||
${isYes} | ${[...truthy, ' yes', 'YeS ', 'y']} | ${[...falsy, 'no', 'string with yes', 2]} |
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.
just curious: does 'YeS '
reflect a value we actually see in the real world?
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.
YeS, and also yES, and also YES 😆
the toBoolean function centralizes the logic for coercing a value and allows the predicate functions to be more specific in what they validate rather than them simply being alais names to broad validation.
Closes #122
✅ Pull Request Checklist:
📝 Test Instructions:
❓ Does this PR introduce a breaking change?
The function
toBoolean
no longer will consider specific values - 'no', 'off', 'n' to be "false" or 'on', 'yes', 'y' to be "true". If that is being relied on that assumption will break; no tests show this to be extant.💬 Other information