Skip to content

Commit

Permalink
Add has method
Browse files Browse the repository at this point in the history
  • Loading branch information
CreaturePhil committed Feb 10, 2016
1 parent d5015ea commit 10ac0b3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ db('profile').get(['phil', 'join_date']); // undefined
db('profile').get(['phil', 'img']); // { width: 55, height: 20 }
```

### has(property)

Checks to see if it has a property.

Parameters:

- ``property``: _String_

Returns: _Boolean_

Example:

```js
{
'bar': 'some kind of data',
'baz': 'some kind of data'
}

console.log(db('foo').has('bar'));
//=> true
console.log(db('foo').has('boo'));
//=> false
```

### delete(property)

Delete a property.
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ module.exports = function(dbDir) {
return cacheObject[file];
},

has: function(prop) {
return cacheObject[file].hasOwnProperty(prop);
},

delete: function(prop) {
delete cacheObject[file][prop];
save();
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ describe('database', () => {

});

describe('has prop', () => {

beforeEach(() => {
db = origindb('db');
});

it('should have a prop', () => {
db('foo').set('yo', 'ho');
assert.deepEqual(db('foo').has('yo'), true);
});

it('should not have a prop', () => {
db('foo').delete('yo');
assert.deepEqual(db('foo').has('yo'), false);
});

});

describe('delete prop', () => {

beforeEach(() => {
Expand Down

0 comments on commit 10ac0b3

Please sign in to comment.