Simple standalone module for reading, writeng and deleting cookies and also for handling localStorage and sessionStorage.
You don't need any additional library.
<script src="/path/to/storage.module.js"></script>
Simple cookie creation:
storageModule.write('cookie', 'cookie value');
Simple cookie reading:
storageModule.read('cookie');
Simple cookie remove:
storageModyle.unset('cookie');
A little better cookie creation:
var cookieLayer = storageModule.setup();
cookieLayer.write('cookie', 'cookie value');
Cookie creation with settings:
var cookieLayer = storageModule.setup(
{
json: true,
path: your/path,
domain: your.domain,
expires: 1, // days to expire
secure: true
raw: true // no encoding
}
);
Simple localStorage creation:
storageModule.setup({storageType: 'localStorage'}).write('localVar', 'local var value');
Simple localStorage reading:
storageModule.setup({storageType: 'localStorage'}).read('localVar');
A better localStorage handling:
var localStorageLayer = storageModule.setup({storageType: 'localStorage'});
localStorageLayer.write('localVar', 'local var value');
if (localStorageLayer.isset('localVar'))
localStorageLayer.read('localVar');
Session Storage is the same like local storage.
Public functions:
function write (key, value)
function read (key)
function unset (key)
function isset (key)
function getAll ()
- Source hosted at GitHub
- Report issues, questions, feature requests on GitHub Issues
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change you make.
Cookie handling by Klaus Hartl jquery-cookie