Javascript Storage Manager
A library that makes the WebStorage easy to use: localStorage
, sessionStorage
and Cookies
(sessionStorage
and Cookies
are in progress: #2, #3).
Install
bower
$ bower install js-storage-manager
npm
$ npm install js-storage-manager
Git
$ git clone https://github.com/bjoern-hempel/js-storage-manager.git
or
$ git clone git@github.com:bjoern-hempel/js-storage-manager.git
Getting started
bower
$ mkdir webproject && cd webproject
$ bower install js-storage-manager
$ vi index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple js-storage-manager example</title>
<script src="bower_components/js-storage-manager/dist/storage-manager.min.js"></script>
</head>
<body>
<script>
var sm = new StorageManager('namespace');
sm.set('data', [{id: 123, name: 'Name 1'}, {id: 123, name: 'Name 2'}]);
document.write(JSON.stringify(sm.get('data')));
</script>
</body>
</html>
npm
The direct way (the old javascript way)
$ mkdir webproject && cd webproject
$ npm install js-storage-manager
$ vi index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple js-storage-manager example</title>
<script src="node_modules/js-storage-manager/dist/storage-manager.min.js"></script>
</head>
<body>
<script>
var sm = new StorageManager('namespace');
sm.set('data', [{id: 123, name: 'Name 1'}, {id: 123, name: 'Name 2'}]);
document.write(JSON.stringify(sm.get('data')));
</script>
</body>
</html>
The webpack way (the modern javascript way)
If you are interested to use this library on the modern javascript way, see here.
Git
$ mkdir webproject && cd webproject
$ mkdir vendor && cd vendor
$ git clone https://github.com/bjoern-hempel/js-storage-manager.git
$ cd ..
$ vi index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple js-storage-manager example</title>
<script src="vendor/js-storage-manager/dist/storage-manager.min.js"></script>
</head>
<body>
<script>
var sm = new StorageManager('namespace');
sm.set('data', [{id: 123, name: 'Name 1'}, {id: 123, name: 'Name 2'}]);
document.write(JSON.stringify(sm.get('data')));
</script>
</body>
</html>
The next steps
How to use the StorageManager in the easiest way
var sm = new StorageManager('namespace');
var data_initial = [{id: 1, name: 'Name 1'}, {id: 2, name: 'Name 2'}];
sm.set('data', data_initial);
var data_from_web_storage = sm.get('data');
How to use multiple namespaces
var namespace_1 = 'namespace1';
var namespace_2 = 'namespace2';
var sm_1 = new StorageManager(namespace_1);
var sm_2 = new StorageManager(namespace_2);
var data_initial_1 = [{id: 1, name: 'Name 1'}, {id: 2, name: 'Name 2'}];
var data_initial_2 = [{id: 3, name: 'Name 3'}, {id: 4, name: 'Name 4'}];
sm.set('data', data_initial_1);
sm.set('data', data_initial_2);
var data_from_web_storage_1 = sm_1.get('data');
var data_from_web_storage_2 = sm_2.get('data');
How to manage the storage yourself
var sm = new StorageManager('namespace');
var data_initial = [{id: 1, name: 'Name 1'}, {id: 2, name: 'Name 2'}];
var storage = sm.getStorage();
storage.data = data_initial;
sm.setStorage(storage)
How to let the StorageManager automatically save changes to the storage data object in web storage
var sm = new StorageManager('namespace');
var data_initial = [{id: 1, name: 'Name 1'}, {id: 2, name: 'Name 2'}];
var observable = true;
var storage = sm.getStorage(observable);
storage.data = data_initial;
How to create and use a queue list
var sm = new StorageManager('namespace');
var queue_data_1 = {id: 1, name: 'Name 1'};
var queue_data_2 = {id: 2, name: 'Name 2'};
var qm = sm.initQueue();
qm.push(queue_data_1);
qm.push(queue_data_2);
var number_of_queue_items = qm.getNumber();
var queue = qm.getAll();
var next_queue_item = qm.getNext();
var next_queue_item = qm.deleteNext();
How to use your own queue namespace or multiple instances of a queue within a namespace
var sm = new StorageManager('namespace');
var queue_data_1 = {id: 1, name: 'Name 1'};
var queue_data_2 = {id: 2, name: 'Name 2'};
var qm = sm.initQueue('my_queue', true);
How to get the LocalStorage area completely managed by the StorageManager
var sm = new StorageManager('namespace');
var local_storage_managed_by_sm = sm.getLocalStorage();
Maintenance
- Checkout the repository
$ git clone git@github.com:bjoern-hempel/js-storage-manager.git && cd js-storage-manager
$ npm install
- Extend, fix bugs in classes below
/src
folder. - Write more tests below the
/test
folder. - Run the tests.
$ npm test
or
$ npm run test:unit
- Build the
/dist
files
$ npm run build
- Change the version number
$ vi package.json
...
"version": "0.0.14",
...
- Commit your changes
$ git add [file1] [file2] [etc.]
$ git commit -m "my bugfixes" .
$ git push
- Tag your version
$ git tag v0.0.14
$ git push origin v0.0.14
- Create Release
$ gren release
Adapt the changelog text to github if necessary: changelog. Show all commits:
$ git log --oneline --decorate
- Update CHANGELOG.md
$ gren changelog --override
$ git commit -m "Change changelog" .
$ git push
- Publish to npm
$ npm publish
A. Authors
B. Changelog
Changes are tracked as GitHub releases or in reverse order here.
C. License
This library is licensed under the MIT License - see the LICENSE.md file for details