浏览器存储API封装:jaadi.js
jopen
10年前
Jaadi 提供简单,易于使用和抽象API来访问浏览器存储,支持许多由DOM, W3C, Browser specific (Chrome) 提供的存储技术和用户定义的存储。Jaadi提供了基本的CRUD操作,能够访问以下存储实现:
- Browser DOM's default property map
{}
- Browser Cookie
document.cookies
- W3C's
window.localStorage
- W3C's
window.sessionStorage
- Chrome's
chrome.storage.local
API 使用
Jaadi 提供了这些基本的 CRUD 方法
- get
- put
- remove
- size
- items
Usage
var dom = Jaadi.createInstance("dom")
put (key,value)
create an entry into the storage
dom.put("a",10); //put a literal dom.put("person", {name:"Name","age":10}); //put a JSON
get(key)
get the item from storage using the keys
var val = dom.get("a"); var person = dom.get("person"); //get back a JSON object
remove(key)
remove the entry from storage
dom.remove("person"); //remove the person object