-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Object is empty or not | ||
* | ||
* {@link https://stackoverflow.com/a/34491966/1284255} | ||
* @version 0.0.1 | ||
* | ||
* @param {Object} obj | ||
* @returns {boolean} | ||
* | ||
* @example | ||
* isEmptyObject({}); //=> true | ||
* isEmptyObject({foo: 1}); //=> false | ||
*/ | ||
function isEmptyObject(obj) { | ||
for (let key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
module.exports = isEmptyObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import test from 'ava'; | ||
import isEmptyObject from '.'; | ||
|
||
test('should return `true` for empty object', t => { | ||
t.is(isEmptyObject({}), true); | ||
}); | ||
|
||
test('should return `false` for not empty object', t => { | ||
t.is(isEmptyObject({foo: 1}), false); | ||
}); |