-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conditional Validation for parameter algorithm in isHash function #2296
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: kushagra-raj.tiwari <[email protected]>
Signed-off-by: kushagra-raj.tiwari <[email protected]>
Signed-off-by: kushagra-raj.tiwari <[email protected]>
…tion. Signed-off-by: kushagra-raj.tiwari <[email protected]>
…in isHash function. Signed-off-by: kushagra-raj.tiwari <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2296 +/- ##
=======================================
Coverage 99.95% 99.95%
=======================================
Files 107 108 +1
Lines 2454 2458 +4
Branches 619 622 +3
=======================================
+ Hits 2453 2457 +4
Partials 1 1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: kushagra-raj.tiwari <[email protected]>
src/lib/util/validateKey.js
Outdated
@@ -0,0 +1,6 @@ | |||
export default function validateKey(object, key, errorMessage) { | |||
if (object[key] === undefined) { |
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.
if (object[key] === undefined) { | |
if(object[key]) { | |
return true; | |
} | |
throw new Error(errorMessage); |
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.
@Daniyal-Qureshi
Thanks for your suggestion. But, if(object[key]) will result false if object[key] is any falsy value like 0, "" (empty string), null, etc. This will defeat the purpose of the function validateKey.
I used a better way of checking the key of any object. Please provide your suggestions on that code.
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.
@KUSHAGRARAJTIWARI Previously, you were checking the value of the given key,I suggested the better way to check if the value is undefined, I think you need to check whether is key is present in the object or not.
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, you are correct. I changed the code and am now using the hasOwnProperty() method. This method sends true if the key is present in the object irrespective of the corresponding value. Using Javascript utility functions is good for code.
After your comment, I recollected that there is a function hasOwnProperty() to check if any key is present in the object or not. Thanks for your comment.
Signed-off-by: kushagra-raj.tiwari <[email protected]>
Signed-off-by: kushagra-raj.tiwari <[email protected]>
Issue: #2295
Checklist