A Web Storage interface for Cookie.
$ bower install cookie-storage
or
$ npm install cookie-storage
window.cookieStorage = new CookieStorage();
// Web Storage interface
cookieStorage.length === 0;
cookieStorage.setItem('key', 'value');
cookieStorage.length === 1;
cookieStorage.key(0) === 'key';
cookieStorage.getItem('key') === 'value';
cookieStorage.removeItem('key');
cookieStorage.length === 0;
cookieStorage.setItem('k1', 'v1');
cookieStorage.setItem('k2', 'v2');
cookieStorage.length === 2;
cookieStorage.clear();
cookieStorage.length === 0;
// Cookie options
cookieStorage.setItem('key', 'value', {
path: '/',
domain: 'example.com',
expires: new Date(),
secure: true
});
See npm run
.