-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Add is.empty() #16
Add is.empty() #16
Conversation
index.js
Outdated
@@ -163,4 +163,12 @@ is.inRange = (x, range) => { | |||
|
|||
is.infinite = x => x === Infinity || x === -Infinity; | |||
|
|||
is.empty = value => { |
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.
you've got quite a lot going on in this method.
- get rid of unnecessary wrapping
( )
. value.length === 0
over!value.length
- you basically have 3 assertions inside (aka
assertion1 || assertion2 || assertion3
). extract each assertion to a helper method (likehasPromiseAPI
), and invoke them insideis.empty
. This will also help identify which case each assertion relates to, and that will also help clarify which part of the method each assertion in the tests relates to. - what is the outcome of
is.empty(undefined)
oris.empty(null)
? we need to make sure that all cases are taken care of, as the README states,
readme.md
Outdated
@@ -150,6 +150,11 @@ is.inRange(3, 10); | |||
Check if `value` is `Infinity` or `-Infinity`. | |||
|
|||
|
|||
##### .empty(value) | |||
|
|||
Returns `true` if `value` is an empty string, array, object, map, or set. |
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.
Rephrase it to match all other methods:
Check if
value
is an empty string, array, object, map or set
@@ -373,3 +373,26 @@ test('is.inRange', t => { | |||
test('is.infinite', t => { | |||
testType(t, 'infinite', ['number']); | |||
}); | |||
|
|||
test('is.empty', t => { |
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.
add cases for null
and undefined
.
@kodie nice PR, personally been waiting for this in my app. Couple of changes for readability and clean code, but it seems fine otherwise. |
@gioragutt Fixing those right now! Quick question, what should booleans return? is.empty(true);
is.empty(false); ? |
@kodie not quite sure, I believe that @sindresorhus your thought? |
@gioragutt I've made the requested changes. I made it just return true if given a falsy value. So |
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.
Good changes. Waiting for @sindresorhus to review
Looks good. Thank you @kodie. Keep 'em coming 👌😎 |
Added the
is.empty(value)
function as mentioned in #1.