Skip to content

Commit

Permalink
Merge b4eec55 into 571be4f
Browse files Browse the repository at this point in the history
  • Loading branch information
dusansimic committed Feb 13, 2019
2 parents 571be4f + b4eec55 commit 1a53ae2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Expand Up @@ -86,6 +86,10 @@ class Keyv extends EventEmitter {
.then(() => true);
}

async has(key) {
return Boolean(await this.get(key, { raw: true }));
}

delete(key) {
key = this._getKeyPrefix(key);
const store = this.opts.store;
Expand Down
8 changes: 8 additions & 0 deletions test/keyv.js
Expand Up @@ -85,6 +85,14 @@ test.serial('.get(key, {raw: true}) returns the raw object instead of the value'
t.is(rawObject.value, 'bar');
});

test.serial('.has(key) where key is the key we are looking for', async t => {
const store = new Map();
const keyv = new Keyv({ store });
await keyv.set('foo', 'bar');
t.is(await keyv.has('foo'), true);
t.is(await keyv.has('fizz'), false);
});

test.serial('Keyv uses custom serializer when provided instead of json-buffer', async t => {
t.plan(3);
const store = new Map();
Expand Down

0 comments on commit 1a53ae2

Please sign in to comment.