codecombat/app/lib/storage.coffee

16 lines
386 B
CoffeeScript
Raw Normal View History

2014-01-26 17:44:08 -05:00
module.exports.load = (key) ->
2014-01-03 13:32:13 -05:00
s = localStorage.getItem(key)
return null unless s
try
value = JSON.parse(s)
return value
catch SyntaxError
console.warning('error loading from storage', key)
return null
2014-01-26 17:44:08 -05:00
module.exports.save = (key, value) ->
2014-01-03 13:32:13 -05:00
s = JSON.stringify(value)
2014-01-26 17:44:08 -05:00
localStorage.setItem(key, s)
module.exports.remove = (key) -> localStorage.removeItem key