Skip to content

viniciuswebdev/js-async-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 

Repository files navigation

js-async-storage

A simple javascript library to manage localstorage with some asynchronous functions.

  • The async functions are not concurrent.
  • Works only in browsers with localStorage support, there is no fallbacks.

API

Include de library:

<script src="js-async-storage.js"></script>

Using:

storage = asyncStorage;

Set and get a item:

storage.setItem('key', 'value');
storage.getItem('key');

Getting all items:

storage.getAll();

Give the index and get the key name:

storage.key(0);

Set a temporary value:

storage.setTTL('key', 'value', 100, function(){
    console.log('deleted');
});

Cleaning all keys and values:

storage.clear();

Add value to existing array:

var cars = new Array();
cars[0] = "Saab";
cars[1] = "Volvo";
cars[2] = "BMW";
storage.setItem('cars', cars);

storage.pushArray('cars', 'Fusca');

With async methods, you can give an instruction and pass a function callback to be called after things done.

Get all items:

storage.getAllAsync(function(result){
    console.log(result);
});

Set and get a single value:

storage.setItemAsync('key', 'value', function(){
    storage.getItemAsync('key', function(result){
        console.log(result);
    });
});

Enjoy!!

About

A simple javascript library to manage localstorage with some asynchronous functions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published