loStorage.js

2018-08-09 admin

loStorage.js是什么

什么是loStorage.js,Client-side storage the way it should be – using the HTML5 localStorage API.

loStorage.js介绍、loStorage.js使用

xStore wraps the HTML5 localStorage and sessionStorage APIs to provide client-side storage, mainly targeted at web apps. It allows you to create different data stores that serialize data for you.

In a nutshell:

  • It’s small: 0.8 KB if minified+gzipped and it doesn’t have dependencies
  • xStore serializes Booleans, numbers, strings, arrays and plain objects for you
  • Chaining support
  • It has a cookie.js like interface.
  • You can choose if your storage should be persistent (localStorage) or just for a session (sessionStorage)

Some example code

var store = new xStore("prefix", localStorage);
store.set({
  list: [1, 2],
  counter: 1
});

// Later

store.push('list', 3, 4).increase('counter'); // Chaining is awesome

// And read the values:

store.get('list'); // [1, 2, 3, 4]
store.get('counter'); 2

Another micro library for client-side storage?

Yep, there are already some similar libraries out there, but I decided to write my own one because none didn’t really fit my needs. xStore only supports browers that are somewhat modern. Furthermore it has an interface that makes working with client-side storage a breeze.

Getting started

Read these wiki entries:

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-37619.html

文章标题:loStorage.js

回到顶部