This article recommends 8 javascript libraries that can better handle local storage. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
I tested some local repositories for my current project. Want to know what cool features they have? continue reading.
https://github.com/krasimir/lsbridge
If you have to send a message from one tab to another in the same browser Tabs, you don't have to do it the hard way. The Local storage bridge is here to make the task easier.
Basic usage:
// 发送 lsbridge.send(‘app.message.error’, { error: ‘Out of memory’ }); // 监听 lsbridge.subscribe(‘app.message.error’, function(data) { console.log(data); // { error: ‘Out of memory’ } });
let basil = new Basil(options); basil.set(‘name’, ‘Amy’); basil.get(‘name’); basil.remove(‘name’); basil.reset();
store.set(‘book’, { title: ‘JavaScript’ }); // Store a book store.get(‘book’); // Get stored book store.remove(‘book’); // Remove stored book store.clearAll(); // Clear all keys
lscache.set(‘name’, ‘Amy’, 5); // 数据将在5分钟后过期 lscache.get(‘name’);
Lockr.set(‘name’, ‘Amy’); Lockr.set(‘age’, 28); Lockr.set(‘books’, [{title: ‘JavaScript’, price: 11.0}, {title: ‘Python’, price: 9.0}]);
let barn = new Barn(localStorage); // 原始类型 barn.set(‘name’, ‘Amy’); let name = barn.get(‘name’); // Amy // List barn.lpush(‘names’, ‘Amy’); barn.lpush(‘names’, ‘James’); let name1 = barn.rpop(‘names’); // Amy let name2 = barn.rpop(‘names’); // James
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 } });
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 });
English original address: https://medium.com/javascript-in-plain-english/8-javascript-libraries-for-better-handling-local-storage-d8cd4a05dbfaFor more programming-related knowledge, please visit:
Programming Video Course! !
The above is the detailed content of Use these 8 javascript libraries to handle local storage better! !. For more information, please follow other related articles on the PHP Chinese website!