Skip to content

JQuery Storage is a plugin to simplify access to local and session storage in HTML5

Notifications You must be signed in to change notification settings

swanjr/jQuery-Storage-API

 
 

Repository files navigation

jQuery Storage API

jQuery Storage API is a plugin that simplify access to storages (HTML5) & cookies, add namespace storage functionality and provide compatiblity for old browsers with cookies!

Functionalities:

  • To store object easily, encode/decode it with JSON automatically
  • Ability to define namespace and use it as a specific storage
  • Magic getter and setter to have access at an infinite object level with one call
  • Add jquery.cookie and manage your cookies with this API
  • You want use storage on old browsers? Add jquery.cookie & JSON and JQuery Storage API use cookies to simulate storage!

Storages

Local storage

$.localStorage

Session storage

$.sessionStorage

Cookie storage (only if jquery.cookie added)

$.cookieStorage

Namespace storage

ns=$.initNamespaceStorage('ns_name');
ns.localStorage // Namespace in localStorage
ns.sessionStorage // Namespace in sessionStorage

Public methods on storage

Public methods are usable on all storage objects ($.localStorage, $.sessionStorage or object return by $.initNamespaceStorage)

storage=$.localStorage

get()

Get a variable from a storage

storage.get('foo') // Get storage.foo
storage.get('foo','foo2','foo3'...) // Get storage.foo.foo2.foo3...
storage.get(['foo','foo2']) // Get storage.foo and storage.foo2 in an object ({foo:storage.foo,foo2:storage.foo2})

set()

Set a variable in a storage

storage.set('foo','value') // Set storage.foo to "value"
storage.set('foo','foo2','foo3'...,'value') // Set storage.foo.foo2.foo3... to "value"
storage.set({'foo':'value,'foo2':'value2'}) // Set storage.foo to "value" and storage.foo2 to "value2"

delete()

Delete a variable in a storage

storage.delete('foo') // Delete storage.foo
storage.delete('foo','foo2','foo3'...) // Delete storage.foo.foo2.foo3...
storage.delete(['foo','foo2']) // Delete storage.foo and storage.foo2

deleteAll()

Truncate the storage

storage.deleteAll() // Delete all variables from the storage

setExpires()

Only on cookieStorage. Set expires date in days (default value is null, cookie is valid for session only; only values setted after setExpires() call be affected)

storage.setExpires(10) // Set expiry date to today + 10 days

This method return the storage object, so you can do :

storage.setExpires(10).set('foo','value') // Set expiry date to today + 10 days and set a new cookie with this expiration

Compatibility

JQuery Storage API is compatible with all browsers that support storage and JSON natively.

If you want more compatibility :

About

JQuery Storage is a plugin to simplify access to local and session storage in HTML5

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%