Wechat search [front-end full stack developers] pay attention to this hair loss, stall, sell goods, continue to learn programmers, the first time to read the latest articles, will give priority to two days published new articles. Pay attention to the gift package, you can save a lot of money!

I tested some local repositories for my current project. Want to know what great features they have? Read on.

Local Storage Bridge

Github.com/krasimir/ls…

If you have to send messages from one TAB to another in the same browser, you don’t have to do it the hard way. The Local Storage Bridge makes the task easier here.

Basic use:

/ / sendLsbridge. Send (' app. Message. The error, '{error: ‘Out ofThe memory '});/ / to monitorLsbridge. Subscribe (' app. Message. The error ',function(data) {
  console.log(data); // {error: 'Out of memory'}
});
Copy the code

Basil.js

Bastill. js unifies sessions, localStorage, and cookies, giving you a straightforward way to process data.

Basic use:

let basil = newBasil(options); Basil. Set (" name ", "Amy"); Basil. Get (" name "); Basil. Remove (" name "); basil.reset();Copy the code

store.js

Github.com/marcuswesti…

Store.js handles the data Store like anything else. But there’s more to it, and one of its advanced features gives you deeper access to browser support.

Basic use:

Store. Set (" book ", {title: 'JavaScript'});// Store a bookStore. The get (" book ");// Get stored bookStore. Remove (" book ");// Remove stored book
store.clearAll(); // Clear all keys
Copy the code

lscache

Github.com/pamelafox/l…

It is similar to the localStorage API. In fact, it is a wrapper for localStorage and uses HTML5 to emulate the memcaches function. Find more features in the documentation above.

Basic use:

Lscache. Set (' name ', 'Amy',5); // The data will expire after 5 minutesLscache. Get (" name ");Copy the code

Lockr

Lockr is built on top of localStorage API. It provides some useful ways to work with local data more easily.

What makes you want to use this library instead of the localStorage API?

Well, the localStorage API only allows you to store strings. If you want to store a number, you first need to convert the number to a string. This doesn’t happen in Lockr because Lockr allows you to store more data types and even objects.

Basic use:

Lockr. Set (" name ", "Amy"); Lockr. Set (" age ",28); [{Lockr. Set (' books',title: ‘JavaScript’, price: 11.0}, {title: ‘Python’, price: 9.0}]);
Copy the code

Barn

github.com/arokor/barn

Barn provides an API similar to Redis on top of localStorage. If persistence is important, then you will need this library to keep the data in state in case of errors.

Basic use:

let barn = new Barn(localStorage);

// Primitive typeBarn. Set (" name ", "Amy");letName = barn. Get (" name ");// Amy

// ListBarn. Lpush (" names ", "Amy"); Barn. Lpush (' names', 'James');letName1 = barn. Rpop (" names ");// Amy
letName2 = barn. Rpop (" names ");// James
Copy the code

localForage

Github.com/localForage…

This simple and fast library will improve the offline experience of the Web using asynchronous storage through IndexedDB or WebSQL. It is similar to localStorage, but has callback capabilities.

Basic use:

Localforage. SetItem (' name ', 'Amy',function(error, value) {
  // Do something}); Localforage. The getItem (' name ',function(error, value) {
  if (error) {
    console.log (' an error occurs "); }else {
    // Do something with the value}});Copy the code

What’s amazing is that it provides documentation in Chinese

crypt.io

Github.com/jas-/crypt….

Crypt. IO uses standard JavaScript encryption libraries for secure browser storage. When using crypto. IO, there are three storage options: sessionStorage, localStorage, or cookie.

Basic use:

let storage = crypto;
let book = { title: ‘JavaScript’, price: 13}; Storage. Set (' book, the book,function(error, results) {
  if (error) {
    throw error;
  }
  
  // Do something}); Storage. The get (" book ",function(error, results) {
  if (error) {
    throw error;
  }
  // Do something
});
Copy the code

Do you know of any other local repositories? Why use it? Let me know in the comments below!