GithubHelp home page GithubHelp logo

rstorage's Introduction

rStorage

jQuery rStorage Plugin

localStorage and sessionStorage helper utility for jQuery

rStorage simplify the usage of localStorage and sessionStorage with JSON objects.

If you have any idea about improving this plugin please let me know

Functionalities

  • Simple namespacing
  • Store objects and encoding, decoding to or from JSON happens automatically
  • Same function call for getters and setters
  • Setters and getters recognize dot notation format
  • Integrated unit tests

How to use

The API is the same for both storages.

Setter

var myObject = {
  level1 : {
     level2 : {
        level3 : 'level3'
     }
  }
}

$.localStorage('testNamespace', myObject);     //setter

//updating an existing key somewhere deep inside the object
$.localStorage(
    'testNamespace.level1.level2',
    {
        foo : {
            bar : 'Gauranga!'
        }
    });

//insert a new key deeply
$.localStorage(
    'testNamespace.aNew.deeply.foo',
    {
        bar : 'Gauranga!'
    });

Getter

$.localStorage('testNamespace');      //getter
$.localStorage('testNamespace.level1');      //dot notation getter

Removing parts by dot notation

$.localStorage.remove('testNamespace.level1.level2');

Same examples for sessionStorage

$.sessionStorage('testNamespace');     //getter, it does not see what we have in $.localStorage
$.sessionStorage('testNamespace',
    {
       book : {
          chapter1: {
             title : 'First Chapter',
             pages : 200
          }
          chapter2: {
             title : 'Second Chapter',
             pages : 300
          }
       }
    });

$.sessionStorage(
    'testNamespace.level1.level2',
    {
        foo : {
            bar : 'Gauranga!'
        }
    });

$.sessionStorage(
    'testNamespace.aNew.deeply.foo',
    {
        bar : 'Gauranga!'
    });


$.sessionStorage('testNamespace');    //getter will return our book object

rstorage's People

Contributors

rrd108 avatar

Watchers

 avatar

rstorage's Issues

add deep property

$.sessionStorage('testNamespace', {});
$.sessionStorage('testNamespace.otherKey.newProp', 'gaura');

key reject

Az alabbi problemaba futottam:

$.localStorage('user', userObj); // userObj egy json object
$.localStorage('user.akarmi', mezo); // az 'akarmi' kulcs nem letezik, ezert hibat dob

Ezt pl. ki tudom ugy kuszobolni, hogy:

var userObj = $.localStorage('user');
userObj.akarmi = mezo;
$.localStorage('user', userObj);

De ez egy kicsit korulmenyes. Szerinted lenne ertelme egy “append” funkcio hozzaadasanak a plugin-hez? Azaz, ha egy mar letezo object-hez szeretnek egy uj tulajdonsagot hozzafuzni, azt egyszerubben meg lehessen oldani (mint pl. a peldam masodik sora)?

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.