Skip to content

HTML5 localStorage abstraction with fallback on cookies

Notifications You must be signed in to change notification settings

Monwara/Memento

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Memento

Simple abstraction layer for localStorage API with fallback on cookies.

Overview

Memento is a HTML5 localStorage API abstraction with automatic fallback on cookies for browsers that do not support localStorage.

It can be used in many ways, but it is most useful for storing simple values identified by a key.

For browsers that only support cookies, Memento coerces values to strings, but this might change in future. For localStorage-capable browsers, Memento will store wahtever values you pass it. For now, it's safest if you use only string values, and use JSON to store complex values.

Installation

Memento can be used either by adding it as a <script> tag, or by using AMD-compliant module loader such as RequireJS.

<script src="js/memento.js"></script>

or:

define(['memento'], function(memento) {

});

memento.set(key, value)

You can use memento.set() call to set a value for a particular key. For example:

memento.set('foo', 'bar');

The above sets foo key to value 'bar'.

memento.get(key, def)

The memento.get() call is used to get the value of a particular key. If key does not exist, it will supply the value of the second argument def, which is undefined by default.

memento.unset(key)

You can unset the value of a key by calling memento.unset(), and passing it the key.

Cookie expiration

Cookies are expired after one year, so, unlike localStorage, they do not last for eternity.

License

Copyright (c)2012 by Monwara LLC / Branko Vukelic branko@monwara.com All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

HTML5 localStorage abstraction with fallback on cookies

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published