Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

idb-kv-store

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb-kv-store - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

2

idbkvstore.min.js

@@ -1,1 +0,1 @@

(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var r;if(typeof window!=="undefined"){r=window}else if(typeof global!=="undefined"){r=global}else if(typeof self!=="undefined"){r=self}else{r=this}r.IdbKeyStore=e()}})(function(){var e,r,n;return function e(r,n,t){function o(u,f){if(!n[u]){if(!r[u]){var c=typeof require=="function"&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var s=new Error("Cannot find module '"+u+"'");throw s.code="MODULE_NOT_FOUND",s}var a=n[u]={exports:{}};r[u][0].call(a.exports,function(e){var n=r[u][1][e];return o(n?n:e)},a,a.exports,e,r,n,t)}return n[u].exports}var i=typeof require=="function"&&require;for(var u=0;u<t.length;u++)o(t[u]);return o}({"/":[function(e,r,n){r.exports=o;var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;function o(e){var r=this;if(!(this instanceof o))return new o(e);if(!e)e={};r._db=null;r._queue=[];var n=t.open(e.name||"idb-key-store");n.onerror=function(r){var n=new Error("IDB error");n.event=r;if(e.onerror){e.onerror(n)}else{throw n}};n.onsuccess=function(n){r._db=n.target.result;r._drainQueue();if(e.onready)e.onready()};n.onupgradeneeded=function(e){var r=e.target.result;r.createObjectStore("kv")}}function i(e){var r={cb:e};if(typeof Promise==="function"&&e==null){r.promise=new Promise(function(e,n){r.cb=function(r,t){if(r)return n(r);else return e(t)}})}if(!r.cb)r.cb=function e(){};return r}o.prototype.get=function(e,r){var n=this;var t=i(r);if(!n._db){n._queue.push({type:"get",key:e,cb:t.cb})}else if(Array.isArray(e)){var o=[];var u=false;var f=0;e.forEach(function(r,i){n.get(e[i],function(r,n){if(u)return;if(r){u=true;t.cb(r)}o[i]=n;f++;if(f===e.length)t.cb(null,o)})})}else{var c=n._db.transaction(["kv"],"readonly").objectStore("kv").get(e);c.onsuccess=function(e){t.cb(null,e.target.result)}}return t.promise};o.prototype.set=function(e,r,n){var t=this;var o=i(n);if(!t._db){t._queue.push({type:"set",key:e,value:r,cb:o.cb})}else{var u=t._db.transaction(["kv"],"readwrite").objectStore("kv").put(r,e);u.onsuccess=function(){o.cb(null)}}return o.promise};o.prototype._drainQueue=function(){var e=this;for(var r=0;r<e._queue.length;r++){var n=e._queue[r];if(n.type==="get"){e.get(n.key,n.cb)}else if(n.type==="set"){e.set(n.key,n.value,n.cb)}}e._queue=null}},{}]},{},[])("/")});
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var r;if(typeof window!=="undefined"){r=window}else if(typeof global!=="undefined"){r=global}else if(typeof self!=="undefined"){r=self}else{r=this}r.IdbKeyStore=e()}})(function(){var e,r,n;return function e(r,n,t){function o(u,f){if(!n[u]){if(!r[u]){var s=typeof require=="function"&&require;if(!f&&s)return s(u,!0);if(i)return i(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var a=n[u]={exports:{}};r[u][0].call(a.exports,function(e){var n=r[u][1][e];return o(n?n:e)},a,a.exports,e,r,n,t)}return n[u].exports}var i=typeof require=="function"&&require;for(var u=0;u<t.length;u++)o(t[u]);return o}({"/":[function(e,r,n){r.exports=o;var t=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB;function o(e,r){var n=this;if(!e)throw new Error("A name must be supplied");if(!(this instanceof o))return new o(e,r);if(!r)r={};n._db=null;n._queue=[];var i=t.open(e);i.onerror=function(e){var n=new Error("IDB error");n.event=e;if(r.onerror){r.onerror(n)}else{throw n}};i.onsuccess=function(e){n._db=e.target.result;n._drainQueue();if(r.onready)r.onready()};i.onupgradeneeded=function(e){var r=e.target.result;r.createObjectStore("kv")}}function i(e){var r={cb:e};if(typeof Promise==="function"&&e==null){r.promise=new Promise(function(e,n){r.cb=function(r,t){if(r)return n(r);else return e(t)}})}if(!r.cb)r.cb=function e(){};return r}o.prototype.get=function(e,r){var n=this;var t=i(r);if(!n._db){n._queue.push({type:"get",key:e,cb:t.cb})}else if(Array.isArray(e)){var o=[];var u=false;var f=0;e.forEach(function(r,i){n.get(e[i],function(r,n){if(u)return;if(r){u=true;t.cb(r)}o[i]=n;f++;if(f===e.length)t.cb(null,o)})})}else{var s=n._db.transaction(["kv"],"readonly").objectStore("kv").get(e);s.onsuccess=function(e){t.cb(null,e.target.result)}}return t.promise};o.prototype.set=function(e,r,n){var t=this;var o=i(n);if(!t._db){t._queue.push({type:"set",key:e,value:r,cb:o.cb})}else{var u=t._db.transaction(["kv"],"readwrite").objectStore("kv").put(r,e);u.onsuccess=function(){o.cb(null)}}return o.promise};o.prototype._drainQueue=function(){var e=this;for(var r=0;r<e._queue.length;r++){var n=e._queue[r];if(n.type==="get"){e.get(n.key,n.cb)}else if(n.type==="set"){e.set(n.key,n.value,n.cb)}}e._queue=null}},{}]},{},[])("/")});

@@ -5,5 +5,6 @@ module.exports = IdbKeyStore

function IdbKeyStore (opts) {
function IdbKeyStore (name, opts) {
var self = this
if (!(this instanceof IdbKeyStore)) return new IdbKeyStore(opts)
if (!name) throw new Error('A name must be supplied')
if (!(this instanceof IdbKeyStore)) return new IdbKeyStore(name, opts)
if (!opts) opts = {}

@@ -14,3 +15,3 @@

var request = IDB.open(opts.name || 'idb-key-store')
var request = IDB.open(name)

@@ -17,0 +18,0 @@ request.onerror = function (event) {

{
"name": "idb-kv-store",
"version": "1.0.0",
"version": "2.0.0",
"description": "Persistent key-value store for web browsers backed by IndexDB",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

# idb-kv-store [![Build Status](https://travis-ci.org/xuset/idb-kv-store.svg?branch=master)](https://travis-ci.org/xuset/idb-kv-store)
# idb-kv-store [![Build Status](https://travis-ci.org/xuset/idb-kv-store.svg?branch=master)](https://travis-ci.org/xuset/idb-kv-store) [![npm](https://img.shields.io/npm/v/idb-kv-store.svg)](https://npmjs.org/package/idb-kv-store)

@@ -14,4 +14,4 @@ Persistent key-value store for web browsers backed by IndexDB

```js
var IdbKvStore = require('idb-kv-store')
var store = new IdbKvStore()
var Store = require('idb-kv-store')
var store = new Store('your stores name')

@@ -29,4 +29,4 @@ // Store the value 'def' at key 'abc'

```js
var IdbKvStore = require('idb-kv-store')
var store = new IdbKvStore()
var Store = require('idb-kv-store')
var store = new Store('your stores name')

@@ -41,8 +41,7 @@ // Store the value 'def' at key 'abc'

### `store = new IdbKvStore([opts])`
### `store = new Store(name, [opts])`
Instantiates a new key-value store.
Instantiates a new key-value store. `name` is the name of the database used to persist the data. So multiple Store instances with the same name will be sharing the same data.
`opts` can take the following options:
* `opts.name` - The name of the IndexDB database to open
* `opts.onready` - A zero argument function to call when the IndexDB database is open

@@ -49,0 +48,0 @@ * `opts.onerror` - This function is called when IndexDB experiences an error. It accepts one error argument. If this is undefined, the error is thrown instead.

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc