Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add .isEmpty(obj)

  • Loading branch information...
commit 23881899ff383bb59b25dfae69647ce15bdcc161 1 parent 78e2708
@tj tj authored
Showing with 27 additions and 23 deletions.
  1. +8 −23 Readme.md
  2. +12 −0 index.js
  3. +7 −0 test/object.js
View
31 Readme.md
@@ -11,37 +11,22 @@ is.date(obj);
```
## API
- - [.keys(obj)](#keysobj)
- - [.values(obj)](#valuesobj)
- - [.length(obj)](#lengthobj)
-<a name="" />
-
-<a name="keysobj" />
+
### .keys(obj)
-should return the keys of an object.
-```js
-var obj = { name: 'tobi', age: 1 };
-object.keys(obj).should.eql(['name', 'age']);
-```
+ Return the keys for `obj`.
-<a name="valuesobj" />
### .values(obj)
-should return the values of an object.
-```js
-var obj = { name: 'tobi', age: 1 };
-object.values(obj).should.eql(['tobi', 1]);
-```
+ Return the values for `obj`.
-<a name="lengthobj" />
### .length(obj)
-should return key count.
-```js
-var obj = { name: 'tobi', age: 1 };
-object.length(obj).should.equal(2);
-```
+ Return the number of keys for `obj`.
+
+### .isEmpty(obj)
+
+ Check if `obj` is empty.
## License
View
12 index.js
@@ -51,4 +51,16 @@ exports.values = function(obj){
exports.length = function(obj){
return exports.keys(obj).length;
+};
+
+/**
+ * Check if `obj` is empty.
+ *
+ * @param {Object} obj
+ * @return {Boolean}
+ * @api public
+ */
+
+exports.isEmpty = function(obj){
+ return 0 == exports.length(obj);
};
View
7 test/object.js
@@ -24,4 +24,11 @@ describe('.length(obj)', function(){
var obj = { name: 'tobi', age: 1 };
object.length(obj).should.equal(2);
})
+})
+
+describe('.isEmpty()', function(){
+ it('should check if the object is empty', function(){
+ object.isEmpty({}).should.be.true;
+ object.isEmpty({ foo: 'bar' }).should.be.false;
+ })
})
Please sign in to comment.
Something went wrong with that request. Please try again.