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

yach.util.indexeddb

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yach.util.indexeddb - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

lib/index copy.js

2

babel.config.js

@@ -6,2 +6,2 @@ module.exports = function (api) {

};
};
};

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

module.exports = require('./lib/index.js');
module.exports = require('./lib/index.js');
/**
* 基于dexie封装了下indexedDB的存取
* 基于localforage封装了下indexedDB的存取
* @author lcq
*/
import Dexie from 'dexie';
import localforage from 'localforage';
class IndexedDB{
constructor(tableName, dbName = 'yach.cache'){
class IndexedDB {
constructor(tableName, dbName = 'yach.cache.new') {
this.tableName = tableName;
this.dbName = dbName;
this.valueKey = 'data';
this.db = new Dexie(dbName);
this.db.version(2).stores({ [tableName]: `id` });
this.localforage = localforage;
if(localStorage.getItem('__debugDB')){// 用于调试
window.db = this.db;
localforage.config({
//driver : localforage.INDEXEDDB, // Force WebSQL; same as using setDriver()
name : dbName,
version : 2.0,
// size : 4980736, // Size of database, in bytes. WebSQL-only for now.
storeName : tableName, // Should be alphanumeric, with underscores.
description : 'some description'
});
if (localStorage.getItem('__debugDB')) {
// 用于调试
window.localforage = localforage;
}
}
setItem(key, value){
return this.db.table(this.tableName).put({id: key, [this.valueKey]: value})
async setItem(key, value) {
try {
return await localforage.setItem(key, value);
} catch (error) {
console.error('indexeddb setItem', error);
}
}
async getItem(key){
const teamCache = await this.db[this.tableName].get({id: key});
return teamCache ? teamCache[this.valueKey] : null;
async getItem(key) {
try {
const teamCache = await localforage.getItem(key);
return teamCache;
} catch (error) {
console.error('indexeddb getItem', error);
return null;
}
}
deleteItem(key){
return this.db.table(this.tableName).delete(key);
async deleteItem(key) {
try {
return await localforage.removeItem(key);
} catch (error) {
console.error('indexeddb deleteItem', error);
}
}
clearItem(){
return this.db.table(this.tableName).clear();
async clear() {
try {
await localforage.clear(key);
} catch (error) {
console.error('indexeddb clear', error);
}
}
}
export default (tableName, dbName) => new IndexedDB(tableName, dbName);
export default (tableName, dbName) => new IndexedDB(tableName, dbName);
{
"name": "yach.util.indexeddb",
"version": "0.0.1",
"license": "MIT",
"description": "封装indexeddb方法 用于yach的缓存",
"main": "index.js",
"author": "Beijing Yidu Huida Education Technology Co., Ltd.",
"scripts": {},
"dependencies": {
"dexie": "^3.0.2"
},
"devDependencies": {
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4"
}
"name": "yach.util.indexeddb",
"version": "1.0.0",
"license": "MIT",
"description": "封装indexeddb方法 用于yach的缓存",
"main": "index.js",
"author": "Beijing Yidu Huida Education Technology Co., Ltd.",
"scripts": {},
"dependencies": {
"localforage": "^1.9.0"
},
"devDependencies": {
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4"
}
}
# yach.util.indexeddb
封装indexeddb方法 用于yach的缓存
封装 indexeddb 方法 用于 yach 的缓存
## Owner
Chuanqing.Li[lichuanqing@tal.com]
## 安装
```sh

@@ -13,2 +16,3 @@ $ npm i yach.util.indexeddb

## 使用
```js

@@ -23,4 +27,3 @@ import _yachDB from 'yach.util.indexeddb';

await yachDB.setItem(key, value);
await yachDb.clear()
await yachDb.clear();
```

@@ -31,2 +34,3 @@

### 0.0.1.2020.10.21
1. init project
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