-
-
Notifications
You must be signed in to change notification settings - Fork 129
Lodash methods and helper functions #149
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
Changes from 4 commits
d2abdc8
da3696c
ea57830
3884295
3188bf2
2916394
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,6 @@ function isOneOf(word, arr) { | |
| return arr.some(item => lowerWord.indexOf(item.toLowerCase()) !== -1); | ||
| } | ||
|
|
||
| function nullOrEmpty(val) { | ||
| return val == null || val.length === 0; | ||
| } | ||
|
|
||
| function timeStringToMs(timeString, now) { | ||
| const d = new Date(now); | ||
| const parts = timeString.split(':'); | ||
|
|
@@ -29,7 +25,7 @@ function timeStringToMs(timeString, now) { | |
|
|
||
| function duringWorkingHoursOrNotSet(config, now) { | ||
| const {workingHours} = config; | ||
| if (workingHours == null || nullOrEmpty(workingHours.from) || nullOrEmpty(workingHours.to)) { | ||
| if (!workingHours?.from || !workingHours?.to) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd consider checking for null or empty by doing this truthy/falsy check relatively unsafe for reason mentioned above. WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're making a good point generally! In this case I think we're still good though as the check will only be true when workingHours
Which would actually make the check more complex and safer here. |
||
| return true; | ||
| } | ||
| const toDate = timeStringToMs(workingHours.to, now); | ||
|
|
@@ -74,14 +70,12 @@ await refreshConfig(); | |
|
|
||
| export {isOneOf}; | ||
| export {inDevMode}; | ||
| export {nullOrEmpty}; | ||
| export {duringWorkingHoursOrNotSet}; | ||
| export {getDirName}; | ||
| export {config}; | ||
| export {buildHash}; | ||
| export default { | ||
| isOneOf, | ||
| nullOrEmpty, | ||
| duringWorkingHoursOrNotSet, | ||
| getDirName, | ||
| config, | ||
|
|
||
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.
See the previous pr. your check is not the same as mine.
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.
in my case I want to explicitly check for null or empty
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.
Sounds good, I changed it back to the same logic but slimer:
is the same as
as the
if-block will convert everything inside it's brackets to a boolean value for checking, we can inline it:Let me know if that works for you.
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.
But that is not true... (Or I'm missing something here):
Your version: const nullOrEmpty = (str) => Boolean(str?.length);
returns false on empty string.
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 typed it the wrong way, I meant
as an
if-block implicitly converts statements inside it to a boolean for checking it, we can check for!str?.lengthdirectly instead of implementing and callingisNullOrEmpty(str)