jquery存储本地存储
I tested some local storage libraries for my current projects. Want to know what cool features they have? Keep reading.
我为当前项目测试了一些本地存储库。 想知道他们有什么很棒的功能吗? 继续阅读。
本地存储桥 (Local Storage Bridge)
https://github.com/krasimir/lsbridge
https://github.com/krasimir/lsbridge
If you have to send a message from one tab to another in the same browser, you don’t have to do it the hard way. Local storage bridge is here to make the task easier.
如果您必须在同一浏览器中将消息从一个选项卡发送到另一个选项卡,则无需费劲。 本地存储桥可简化任务。
Basic usage:
基本用法:
// Sendinglsbridge.send(‘app.message.error’, { error: ‘Out of memory’ });// Listeninglsbridge.subscribe(‘app.message.error’, function(data) { console.log(data); // { error: ‘Out of memory’ }});
Basil.js (Basil.js)
http://wisembly.github.io/basil.js/
http://wisembly.github.io/basil.js/
Basil.js unifies session, localStorage, and cookie to provide you a straightforward way to work with data.
Basil.js统一了会话,localStorage和cookie,为您提供了一种处理数据的直接方法。
Basic usage:
基本用法:
let basil = new Basil(options);basil.set(‘name’, ‘Amy’);basil.get(‘name’);basil.remove(‘name’);basil.reset();
store.js (store.js)
https://github.com/marcuswestin/store.js
https://github.com/marcuswestin/store.js
Store.js handle data storage like everything else. But there’s more. One of the advanced features is it lets you access browser support deeper.
Store.js像其他所有东西一样处理数据存储。 但是还有更多。 高级功能之一是它使您可以更深入地访问浏览器支持。
Basic usage:
基本用法:
store.set(‘book’, { title: ‘JavaScript’ }); // Store a bookstore.get(‘book’); // Get stored bookstore.remove(‘book’); // Remove stored bookstore.clearAll(); // Clear all keys
缓存 (lscache)
https://github.com/pamelafox/lscache
https://github.com/pamelafox/lscache
It’s similar to localStorage API. In fact, it’s a wrapper of localStorage and emulates memcaches functions using HTML5. Discover more features in the document above.
它类似于localStorage API。 实际上,它是localStorage的包装,并使用HTML5模拟了memcaches函数。 在上面的文档中发现更多功能。
Basic usage:
基本用法:
lscache.set(‘name’, ‘Amy’, 5); // Data will be expired after 5 minuteslscache.get(‘name’);
储物柜 (Lockr)
https://github.com/tsironis/lockr
https://github.com/tsironis/lockr
Lockr is built on top of the localStorage API. It provides you some useful methods to work with local data easier.
Lockr建立在localStorage API之上。 它提供了一些有用的方法来更轻松地处理本地数据。
What makes you want to use this library instead of the localStorage API?
是什么让您想要使用此库而不是localStorage API?
Well, the localStorage API only allows you to store strings. If you want to store a number, you need to convert that number to string first. That doesn’t happen in Lockr because Lockr lets you store more data types even objects.
好吧,localStorage API仅允许您存储字符串。 如果要存储数字,则需要先将该数字转换为字符串。 在Lockr中不会发生这种情况,因为Lockr允许您存储更多的数据类型甚至对象。
Basic usage:
基本用法:
Lockr.set(‘name’, ‘Amy’);Lockr.set(‘age’, 28);Lockr.set(‘books’, [{title: ‘JavaScript’, price: 11.0}, {title: ‘Python’, price: 9.0}]);
谷仓 (Barn)
https://github.com/arokor/barn
https://github.com/arokor/barn
Barn provides a Redis-like API on top of localStorage. If persistence matters then you will need this library to keep the data state in case of errors occur.
Barn在localStorage的顶部提供了类似Redis的API。 如果持久性很重要,那么在发生错误的情况下,您将需要此库来保持数据状态。
Basic usage:
基本用法:
let barn = new Barn(localStorage);// Primitive typesbarn.set(‘name’, ‘Amy’);let name = barn.get(‘name’); // Amy// Listbarn.lpush(‘names’, ‘Amy’);barn.lpush(‘names’, ‘James’);let name1 = barn.rpop(‘names’); // Amylet name2 = barn.rpop(‘names’); // James
本地饲料 (localForage)
https://github.com/localForage/localForage
https://github.com/localForage/localForage
This simple and fast library will improve the offline experience of your web using asynchronous storage via IndexedDB or WebSQL. It’s similar to localStorage but having callbacks as an extra feature.
这个简单而快速的库将通过IndexedDB或WebSQL使用异步存储来改善Web的脱机体验。 它类似于localStorage,但具有回调功能。
Basic usage:
基本用法:
localforage.setItem(‘name’, ‘Amy’, function(error, value) { // Do something});localforage.getItem(‘name’, function(error, value) { if (error) { console.log(‘an error occurs’); } else { // Do something with the value }});
加密 (crypt.io)
https://github.com/jas-/crypt.io
https://github.com/jas-/crypt.io
crypt.io implements secures browser storage with the Standford JavaScript Crypto Libraries. When working with crypto.io, you have three storage options: sessionStorage, localStorage, or cookies.
crypt.io使用Standford JavaScript加密库实现安全的浏览器存储。 使用crypto.io时,有三个存储选项:sessionStorage,localStorage或cookie。
Basic usage:
基本用法:
let storage = crypto;let book = { title: ‘JavaScript’, price: 13 };storage.set(‘book’, book, function(error, results) { if (error) { throw error; } // Do something});storage.get(‘book’, function(error, results) { if (error) { throw error; } // Do something});
Do you know any local storage library else? Why do you use it? Let me know in the comment below
您还知道其他本地存储库吗? 为什么使用它? 在下面的评论中让我知道
进一步阅读 (Further Reading)
普通英语JavaScript (JavaScript In Plain English)
Enjoyed this article? If so, get more similar content by subscribing to Decoded, our YouTube channel!
喜欢这篇文章吗? 如果是这样,请订阅我们的YouTube频道解码,以获得更多类似的内容!
jquery存储本地存储