Sha256: 5e64d4f4441a99f0d3e57f15c0023ca6a9df33d96fd4a3ec6c9ed630384f30d2

Contents?: true

Size: 618 Bytes

Versions: 2

Compression:

Stored size: 618 Bytes

Contents

window.memo =
  set: (key, value)->
    unless value is undefined
      serializedValue = JSON.stringify(value)
      window.localStorage[key] = serializedValue
      value

  get: (key) ->
    if value = localStorage[key]
      try
        JSON.parse(value)
      catch error # It's not valid JSON, so probably set by something using localStorage directly.
        value
    else
      null

  keys: ->
    Object.keys(localStorage)

  delete: (key) ->
    localStorage.removeItem(key)

  clear: ->
    localStorage.clear()

  all: ->
    object = {}
    @keys().map (key) =>
      object[key] = @get(key)
    object

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
memojs-1.0.1 lib/assets/javascripts/memojs.coffee
memojs-1.0.0 lib/assets/javascripts/memojs.coffee