Socket
Socket
Sign inDemoInstall

keyv

Package Overview
Dependencies
0
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

test/helpers/test-store.js

3

package.json
{
"name": "keyv",
"version": "0.1.0",
"version": "0.1.1",
"description": "Simple key/value store with support for multiple backends",

@@ -34,3 +34,2 @@ "main": "src/index.js",

"coveralls": "^2.13.1",
"delay": "^2.0.0",
"eslint-config-xo-lukechilds": "^1.0.0",

@@ -37,0 +36,0 @@ "nyc": "^10.3.2",

@@ -10,11 +10,12 @@ 'use strict';

get(key) {
return Promise.resolve(this.opts.store.get(key)).then(data => {
const store = this.opts.store;
return Promise.resolve(store.get(key)).then(data => {
if (!data) {
return undefined;
}
if (!this.opts.store.ttlSupport && Date.now() > data.expires) {
if (!store.ttlSupport && Date.now() > data.expires) {
this.delete(key);
return undefined;
}
return this.opts.store.ttlSupport ? data : data.value;
return store.ttlSupport ? data : data.value;
});

@@ -25,9 +26,10 @@ }

ttl = ttl || this.opts.ttl;
const store = this.opts.store;
let set;
if (this.opts.store.ttlSupport) {
set = this.opts.store.set(key, value, ttl);
if (store.ttlSupport) {
set = store.set(key, value, ttl);
} else {
const expires = (typeof ttl === 'number') ? (Date.now() + ttl) : undefined;
const data = { value, expires };
set = this.opts.store.set(key, data);
set = store.set(key, data);
}

@@ -38,3 +40,4 @@ return Promise.resolve(set).then(() => value);

delete(key) {
return Promise.resolve(this.opts.store.delete(key));
const store = this.opts.store;
return Promise.resolve(store.delete(key));
}

@@ -41,0 +44,0 @@ }

import test from 'ava';
import delay from 'delay';
import Keyv from '../';
import testStore from './helpers/test-store';

@@ -64,1 +65,4 @@ test('Keyv is a class', t => {

});
const store = new Map();
testStore(store);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc