npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

offline-storage

v0.0.5

Published

an offline storage library that offers a unified set of asynchronous chain and localstorage-like api

Downloads

7

Readme

特性

  • 支持Promise风格异步链式调用
  • 对外暴露一致、简洁的localStorage-like接口api
  • 自动适配当前浏览器下最优的存储驱动
  • 统一key/value键值对式对象存取

支持的驱动

  • indexedDB(优先支持)
  • localStorage(后备支持)

接口暴露

  • set(key,value)
  • get(key)
  • has(key)
  • remove(key)
  • clear()
  • count()
  • forEach(callback)
  • all(...callback)

安装

npm install offline-storage --save

使用

import Storage from 'offline-storage'

参数配置

// 默认配置
const defaultConfig = {
  driver: 'indexedDB',

  // 强制使用某种驱动, 默认false.自适配, true时则不会适配.
  forcibly: false,
  dbName: '',
  storeName: '',
};

如果forcibly使用默认值false,storage将根据浏览器自动适配最佳的驱动,并优先使用indexedDB. 如果想强制指定某一种驱动,只需要将forcibly值设为true. 另外两个参数dbName,storeName分别为indexedDB 的库名与表名。

示例

    let storage = new Storage({
      driver: 'localStorage',
      forcibly: true
    });
    
    storage.get('key')
       .then(function(value) {})
       .catch(function(e){});

    storage.set('key', { something: true })
       .then(function() {})
       .catch(function(e){});

    storage.has('key')
       .then(function(bool) {})
       .catch(function(e){});

    storage.remove('key')
       .then(function() {})
       .catch(function(e){});

    storage.clear()
       .then(function() {})
       .catch(function(e){});

    storage.count()
       .then(function(integer) {})
       .catch(function(e){});

    let func = ()=>{ console.log('and') };
    storage.forEach(func)
       .then(function() {})
       .catch(function(e){});

    let funcs = [func1,func2,func3];
    storage.all(funcs)
       .then(function() {})
       .catch(function(e){});

浏览器兼容性

  • 小容量需求(2~10M),若使用localStorage驱动,兼容到所有现代浏览器和IE8.
  • 大容量需求,使用indexedDB,只兼容最新的现代浏览器.

驱动 | Chorme | Firefox(Gecko) | Internet Explore | Opera | Safari(Webkit) --- | ------ | ---------------| ---------------- | ------|---------- localStorage| 4 | 3.5 | 8 | 10.5 | 4 indexedDB|23、24(webkit)|10、16(moz)|10|15|7.1

存储空间限制

  • localStorage在不同浏览器的不同版本下有不同的容量限制,范围为2~10M。
  • indexedDB驱动总容量没有限制。单个indexedDB在不同浏览器下会有不同的限制。比如firefox对超过50M的Blob会请求权限。

文档参考

http://www.html5rocks.com/en/tutorials/offline/storage/

https://html.spec.whatwg.org/multipage/webstorage.html

https://developer.mozilla.org/zh-CN/docs/Web/API/IndexedDB_API/Using_IndexedDB