idb-keyval
Advanced tools
Comparing version 2.4.2 to 2.5.0
@@ -1,78 +0,91 @@ | ||
var db; | ||
(function() { | ||
'use strict'; | ||
var db; | ||
function getDB() { | ||
if (!db) { | ||
db = new Promise(function(resolve, reject) { | ||
var openreq = indexedDB.open('keyval-store', 1); | ||
function getDB() { | ||
if (!db) { | ||
db = new Promise(function(resolve, reject) { | ||
var openreq = indexedDB.open('keyval-store', 1); | ||
openreq.onerror = function() { | ||
reject(openreq.error); | ||
}; | ||
openreq.onerror = function() { | ||
reject(openreq.error); | ||
}; | ||
openreq.onupgradeneeded = function() { | ||
// First time setup: create an empty object store | ||
openreq.result.createObjectStore('keyval'); | ||
}; | ||
openreq.onupgradeneeded = function() { | ||
// First time setup: create an empty object store | ||
openreq.result.createObjectStore('keyval'); | ||
}; | ||
openreq.onsuccess = function() { | ||
resolve(openreq.result); | ||
}; | ||
}); | ||
openreq.onsuccess = function() { | ||
resolve(openreq.result); | ||
}; | ||
}); | ||
} | ||
return db; | ||
} | ||
return db; | ||
} | ||
function withStore(type, callback) { | ||
return getDB().then(function(db) { | ||
return new Promise(function(resolve, reject) { | ||
var transaction = db.transaction('keyval', type); | ||
transaction.oncomplete = function() { | ||
resolve(); | ||
}; | ||
transaction.onerror = function() { | ||
reject(transaction.error); | ||
}; | ||
callback(transaction.objectStore('keyval')); | ||
function withStore(type, callback) { | ||
return getDB().then(function(db) { | ||
return new Promise(function(resolve, reject) { | ||
var transaction = db.transaction('keyval', type); | ||
transaction.oncomplete = function() { | ||
resolve(); | ||
}; | ||
transaction.onerror = function() { | ||
reject(transaction.error); | ||
}; | ||
callback(transaction.objectStore('keyval')); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
export default { | ||
get: function(key) { | ||
var req; | ||
return withStore('readonly', function(store) { | ||
req = store.get(key); | ||
}).then(function() { | ||
return req.result; | ||
var idbKeyval = { | ||
get: function(key) { | ||
var req; | ||
return withStore('readonly', function(store) { | ||
req = store.get(key); | ||
}).then(function() { | ||
return req.result; | ||
}); | ||
}, | ||
set: function(key, value) { | ||
return withStore('readwrite', function(store) { | ||
store.put(value, key); | ||
}); | ||
}, | ||
delete: function(key) { | ||
return withStore('readwrite', function(store) { | ||
store.delete(key); | ||
}); | ||
}, | ||
clear: function() { | ||
return withStore('readwrite', function(store) { | ||
store.clear(); | ||
}); | ||
}, | ||
keys: function() { | ||
var keys = []; | ||
return withStore('readonly', function(store) { | ||
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari. | ||
// And openKeyCursor isn't supported by Safari. | ||
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function() { | ||
if (!this.result) return; | ||
keys.push(this.result.key); | ||
this.result.continue(); | ||
}; | ||
}).then(function() { | ||
return keys; | ||
}); | ||
} | ||
}; | ||
if (typeof module != 'undefined' && module.exports) { | ||
module.exports = idbKeyval; | ||
} else if (typeof define === 'function' && define.amd) { | ||
define('idbKeyval', [], function() { | ||
return idbKeyval; | ||
}); | ||
}, | ||
set: function(key, value) { | ||
return withStore('readwrite', function(store) { | ||
store.put(value, key); | ||
}); | ||
}, | ||
delete: function(key) { | ||
return withStore('readwrite', function(store) { | ||
store.delete(key); | ||
}); | ||
}, | ||
clear: function() { | ||
return withStore('readwrite', function(store) { | ||
store.clear(); | ||
}); | ||
}, | ||
keys: function() { | ||
var keys = []; | ||
return withStore('readonly', function(store) { | ||
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari. | ||
// And openKeyCursor isn't supported by Safari. | ||
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function() { | ||
if (!this.result) return; | ||
keys.push(this.result.key); | ||
this.result.continue(); | ||
}; | ||
}).then(function() { | ||
return keys; | ||
}); | ||
} else { | ||
self.idbKeyval = idbKeyval; | ||
} | ||
}; | ||
}()); |
{ | ||
"name": "idb-keyval", | ||
"version": "2.4.2", | ||
"version": "2.5.0", | ||
"description": "A super-simple-small keyval store built on top of IndexedDB", | ||
"main": "dist/idb-keyval-cjs.js", | ||
"module": "idb-keyval.js", | ||
"main": "idb-keyval.js", | ||
"typings": "typings.d.ts", | ||
"scripts": { | ||
"build": "del dist && rollup -c && uglifyjs -o dist/idb-keyval-iife.min.js dist/idb-keyval-iife.js" | ||
"build": "uglifyjs idb-keyval.js --screw-ie8 -mc --output dist/idb-keyval-min.js" | ||
}, | ||
@@ -25,5 +24,2 @@ "repository": { | ||
"author": "Jake Archibald", | ||
"contributors": [ | ||
"Benny Powers" | ||
], | ||
"license": "Apache-2.0", | ||
@@ -35,6 +31,4 @@ "bugs": { | ||
"devDependencies": { | ||
"del-cli": "^1.1.0", | ||
"rollup": "^0.56.5", | ||
"uglify-es": "^3.3.9" | ||
"uglify-js": "^2.7.0" | ||
} | ||
} |
@@ -20,3 +20,3 @@ declare module 'idb-keyval' { | ||
const idbKeyVal: IDBKeyVal<string>; | ||
export default idbKeyVal; | ||
export = idbKeyVal; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
7500
6
105