Code Monkey home page Code Monkey logo

jquery-ezstorage's Introduction

jQuery EZStorage

jQuery EZStorage is a plugin that simplifies access to HTML5 storages & cookies. The plugin handles determining where and how to store and retrieve data; in HTML5 Storage if it is available, or defaults to cookies.

Functionalities:


Usage

$.ezstorage(action, key, value, options)

overloaded function to manage 'storage'

  • checks if local/session Storage is implemented in the browser
  • checks if cookies are enabled
  • get/set key:value pairs (in Storage or as a cookie)
  • removes key:value pairs (in Storage or as a cookie)

@param String action

  • the action to perform: - 'enabled' = verify that a storage option is possible - 'get' = get a value from storage; returns null, Scalar, Object - 'set' = set a key:value pair; value converted to JSON String if Object - 'remove' = delete a key:value pair

@param String key

  • the key to store; n/a with enabled

@param Mixed value

  • the value to store; n/a with get or remove

@param Object options

  • options for setting the key:value; Optional - n/a with enabled
  • if using HTMLStorage 'value' converted to an Object; value.expires = expireDate, etc.
  • during 'get', check is made for expired; null returned if expired
  • if expires omitted, sessionStorage used
  • Object:
    • expires: Date object (preferred), Numeric number of days, or parseable date String
    • persist: Boolean; whether to place value in localStorage despite expires being set
    • path: String; only used if cookie,
    • full: Boolean; whether to return the full object stored by ezstorage or just value

@return Mixed

  • 'enabled' = Boolean
  • 'get' = null or stored value; will be Object if Scalar set with an expires
  • 'set' = stored value;
  • 'remove' = always True, if not a javascript error occured.

Shorthand Functions ------------------------- ### `enabled()` Check whether a storage method is available; HTML5 Storage or cookies
$.ezstorage.enabled();

get(key, options = {})

Get an item from a storage. Searches localStorage, sessionStorage, and cookies.

$.ezstorage.get('foo');
$.ezstorage.get('foo', {full:true}); // return {ezstorage:true …} not just 'value'

set(key, value, options = {})

Set an item in a storage. If options.expire or options.persist are set value is stored in localStorage, else sessionStorage/cookie.

  • value is stored as an object: {ezstorage:true, <options>, value:<value>}

    $.ezstorage.set('foo', 'value'); $.ezstorage.set('foo', 'value', {expires:3}); $.ezstorage.set('foo', 'value', {persist:true});

remove(key, options = {})

Delete an item from all storages (local, session, and cookie). Options only used if being stored as a cookie.

storage.remove('foo');

Global Object -------------------------
 $.ezstorage.defaultSettings(); // return settings to {ezstorage: true, path:'/'};
 $.ezstorage.settings = {<your settings>}; // no longer need to pass in function

Compatibility -------------

JQuery EZStroage is compatible with all browsers that support (and have enabled) storage/cookies.

jquery-ezstorage's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rstroet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.