Socket
Socket
Sign inDemoInstall

idb

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb - npm Package Compare versions

Comparing version 2.1.3 to 3.0.0

build/idb.js

10

gulpfile.js

@@ -19,5 +19,5 @@ var gulp = require('gulp');

gulp.task('copy-lib', function() {
gulp.task('copy-build', function() {
return gulp.src([
'lib/idb.js'
'build/idb.js'
]).pipe(gulp.dest('dist'))

@@ -103,3 +103,3 @@ .pipe(reload({stream: true}));

gulp.watch(['test/index.html'], ['copy']);
gulp.watch(['lib/idb.js'], ['copy-lib']);
gulp.watch(['build/idb.js'], ['copy-build']);

@@ -116,3 +116,3 @@ Object.keys(bundlers).forEach(function(key) {

gulp.task('build', function (done) {
runSequence('clean', ['copy', 'js', 'copy-lib'], done);
runSequence('clean', ['copy', 'js', 'copy-build'], done);
});

@@ -123,3 +123,3 @@

gulp.task('serve', function (done) {
runSequence('clean', ['copy', 'js', 'copy-lib'], ['browser-sync', 'watch'], done);
runSequence('clean', ['copy', 'js', 'copy-build'], ['browser-sync', 'watch'], done);
});

@@ -1,25 +0,13 @@

/** This is your entry point to the API. It's exposed to the global scope unless you're using a module system such as browserify, in which case it's the exported object. */
declare var idb: IDBStatic;
export default idb;
declare global {
var idb: IDBStatic;
}
/** This method returns a promise that resolves to a DB.
* @param name The name of the database.
* @param version Optional. The version to open the database with. If the version is not provided and the database exists, then a connection to the database will be opened without changing its version. If the version is not provided and the database does not exist, then it will be created with version 1.
* @param upgradeCallback Optional. Called if version is greater than the version last opened. It's similar to IDB's onupgradeneeded. The callback receives an instance of UpgradeDB.
* @returns A Promise that passes the DB once it has been opened. */
export function openDb(name: string, version?: number, upgradeCallback?: (db: UpgradeDB) => void): Promise<DB>;
/** This is a tiny library that mirrors IndexedDB, but replaces IDBRequest objects with promises.
* This is your entry point to the API. It's exposed to the global scope unless you're using a module system such as browserify, in which case it's the exported object. */
export interface IDBStatic {
/** Behaves like indexedDB.deleteDatabase, but returns a promise.
* @param name The name of the database.
* @returns A Promise that completes once the DB has been removed. */
export function deleteDb(name: string): Promise<void>;
/** This method returns a promise that resolves to a DB.
* @param name The name of the database.
* @param version Optional. The version to open the database with. If the version is not provided and the database exists, then a connection to the database will be opened without changing its version. If the version is not provided and the database does not exist, then it will be created with version 1.
* @param upgradeCallback Optional. Called if version is greater than the version last opened. It's similar to IDB's onupgradeneeded. The callback receives an instance of UpgradeDB.
* @returns A Promise that passes the DB once it has been opened. */
open(name: string, version?: number, upgradeCallback?: (db: UpgradeDB) => void): Promise<DB>;
/** Behaves like indexedDB.deleteDatabase, but returns a promise.
* @param name The name of the database.
* @returns A Promise that completes once the DB has been removed. */
delete(name: string): Promise<void>;
}
/** Similar to equivalent IDBDatabase. */

@@ -26,0 +14,0 @@ export interface DB {

if (typeof indexedDB != 'undefined') {
module.exports = require('./idb.js');
module.exports = require('../build/idb.js');
}
else {
module.exports = {
open: function () {
openDb: function () {
return Promise.reject('IDB requires a browser environment');
},
delete: function () {
deleteDb: function () {
return Promise.reject('IDB requires a browser environment');

@@ -11,0 +11,0 @@ }

{
"name": "idb",
"version": "2.1.3",
"version": "3.0.0",
"description": "IndexedDB but with promises",
"main": "lib/node.js",
"browser": "lib/idb.js",
"module": "lib/idb.mjs",
"browser": "build/idb.js",
"typings": "lib/idb.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "gulp serve"
"build": "rollup lib/idb.mjs --file build/idb.js --format umd --name idb"
},

@@ -19,20 +19,4 @@ "repository": {

"devDependencies": {
"babelify": "^6.1.3",
"browser-sync": "^2.8.2",
"browserify": "^11.0.1",
"del": "^1.2.0",
"es6-promise": "^3.0.2",
"gulp": "^3.9.0",
"gulp-load-plugins": "^0.10.0",
"gulp-size": "^1.2.3",
"gulp-sourcemaps": "^1.5.2",
"gulp-util": "^3.0.6",
"merge-stream": "^0.1.8",
"mocha": "^2.2.5",
"run-sequence": "^1.1.2",
"uglifyify": "^3.0.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.3.1"
"rollup": "^1.0.2"
}
}

@@ -16,8 +16,8 @@ # IndexedDB Promised

```js
import idb from 'idb';
import { openDb, deleteDb } from 'idb';
await idb.open(…);
await openDb(…);
```
Or include [the script](https://github.com/jakearchibald/idb/blob/master/lib/idb.js) as it is, and `idb` will exist on the global scope.
Or include [the script](https://github.com/jakearchibald/idb/blob/master/build/idb.js) as it is, and `idb` will exist on the global scope.

@@ -31,3 +31,3 @@ # Examples

```js
const dbPromise = idb.open('keyval-store', 1, upgradeDB => {
const dbPromise = openDb('keyval-store', 1, upgradeDB => {
upgradeDB.createObjectStore('keyval');

@@ -37,46 +37,28 @@ });

const idbKeyval = {
get(key) {
return dbPromise.then(db => {
return db.transaction('keyval')
.objectStore('keyval').get(key);
});
async get(key) {
const db = await dbPromise;
return db.transaction('keyval').objectStore('keyval').get(key);
},
set(key, val) {
return dbPromise.then(db => {
const tx = db.transaction('keyval', 'readwrite');
tx.objectStore('keyval').put(val, key);
return tx.complete;
});
async set(key, val) {
const db = await dbPromise;
const tx = db.transaction('keyval', 'readwrite');
tx.objectStore('keyval').put(val, key);
return tx.complete;
},
delete(key) {
return dbPromise.then(db => {
const tx = db.transaction('keyval', 'readwrite');
tx.objectStore('keyval').delete(key);
return tx.complete;
});
async delete(key) {
const db = await dbPromise;
const tx = db.transaction('keyval', 'readwrite');
tx.objectStore('keyval').delete(key);
return tx.complete;
},
clear() {
return dbPromise.then(db => {
const tx = db.transaction('keyval', 'readwrite');
tx.objectStore('keyval').clear();
return tx.complete;
});
async clear() {
const db = await dbPromise;
const tx = db.transaction('keyval', 'readwrite');
tx.objectStore('keyval').clear();
return tx.complete;
},
keys() {
return dbPromise.then(db => {
const tx = db.transaction('keyval');
const keys = [];
const store = tx.objectStore('keyval');
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
// openKeyCursor isn't supported by Safari, so we fall back
(store.iterateKeyCursor || store.iterateCursor).call(store, cursor => {
if (!cursor) return;
keys.push(cursor.key);
cursor.continue();
});
return tx.complete.then(() => keys);
});
}
async keys() {
const db = await dbPromise;
return db.transaction('keyval').objectStore('keyval').getAllKeys(key);
},
};

@@ -88,6 +70,6 @@ ```

```js
keyValStore.set('foo', {hello: 'world'});
idbKeyval.set('foo', {hello: 'world'});
// logs: {hello: 'world'}
keyValStore.get('foo').then(val => console.log(val));
idbKeyval.get('foo').then(val => console.log(val));
```

@@ -109,3 +91,3 @@

```js
const dbPromise = idb.open('keyval-store', 2, upgradeDB => {
const dbPromise = openDb('keyval-store', 2, upgradeDB => {
// Note: we don't use 'break' in this switch statement,

@@ -207,5 +189,5 @@ // the fall-through behaviour is what we want.

This is your entry point to the API. It's exposed to the global scope unless you're using a module system such as browserify, in which case it's the exported object.
This is your entry point to the API. It's exposed to the global scope unless you're using a module system such as browserify, in which case it's the exported object. If you are using native ES modules, the functions are provided as individual exports, so you can `import * as idb from 'idb'` or `import { openDb, deleteDb } from 'idb'`.
### `idb.open(name, version, upgradeCallback)`
### `openDb(name, version, upgradeCallback)`

@@ -219,3 +201,3 @@ This method returns a promise that resolves to a `DB`.

```js
idb.open('keyval-store', 2, upgradeDB => {
openDb('keyval-store', 2, upgradeDB => {
// Note: we don't use 'break' in this switch statement,

@@ -232,3 +214,3 @@ // the fall-through behaviour is what we want.

### `idb.delete(name)`
### `deleteDb(name)`

@@ -238,3 +220,3 @@ Behaves like `indexedDB.deleteDatabase`, but returns a promise.

```js
idb.delete('keyval-store').then(() => console.log('done!'));
deleteDb('keyval-store').then(() => console.log('done!'));
```

@@ -285,3 +267,3 @@

```js
idb.open('keyval-store', 1, upgradeDB => {
openDb('keyval-store', 1, upgradeDB => {
switch (upgradeDB.oldVersion) {

@@ -288,0 +270,0 @@ case 0:

Sorry, the diff of this file is not supported yet

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