Browser-Storage 本地存储 localstorage/sessionstorage 的封装,类似于 chrome.storage 的 API

2018-08-02 20:58:14 +08:00
 MinonHeart
// storage
{
  root_key: {
    a: [1,2,3],
    b: false,
    c: {
      d: null
    }
  }
}

为了把上面这种结构拆解成下面的结构

// storage
{
  a: [1,2,3],
  b: false,
  c: {
    d: null
  }
}

按照 chrome.storage 的 API 设计了一个封装库 @semibold/browser-storage

安装

$ npm i @semibold/browser-storage
import {BrowserStorage} from '@semibold/browser-storage';

// APIs
const bs = new BrowserStorage(areaName, options);

BrowserStorage.metadata

bs.storage
bs.available();
bs.get(keys);
bs.getBytesInUse(keys);
bs.set(items);
bs.remove(keys);
bs.clear();

详细的文档请查看 https://github.com/Semibold/Browser-Storage/blob/master/README.md

1708 次点击
所在节点    分享创造
4 条回复
channg
2018-08-04 23:05:19 +08:00
和 localforage 有啥区别吗
MinonHeart
2018-08-05 21:36:27 +08:00
@channg 同步操作,tiny
channg
2018-08-06 18:13:35 +08:00
@MinonHeart localforage 不同步是因为兼容到 ie8
MinonHeart
2018-08-07 00:14:52 +08:00
@channg 不是为了 indexdb 吗?全异步统一的 api

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/476405

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX