Code Monkey home page Code Monkey logo

localstoragemanager's Introduction

LocalStorageManager

A simple wrapper for the localStorage browser API.

Usage

/** Create a new instance of LocalStorageManager
*	@param keyName	A string for the key
*	@param data		The value of the key (an string or object)
*	@param version	[optional] This is a parameter to test against a previous local saved version of the same key. So if the version is different than the local we overwrite it.
*/
var lsm = new LocalStorageManager(keyName, data, [version]); 

/**
*	Write to save data to localStorage (note: this is no merge, everything will be overwritten).
*	@paran data	The value of the key (an string or object)
*	@param keyName [optional] If no name is provided the value provided in the constructor will be used.
*/
lsm.write(data, keyName);

/**
*	Deletes the key from localStorage.
*	@param keyName [optional] If no name is provided the value provided in the constructor will be used and flushed.
*	@return Returns true if the key was found and deleted.
*/
lsm.flush(keyName);
/**
*	Write to save data to localStorage (note: this is no merge, everything will be overwritten).
*	@param keyName [optional] If no name is provided the value provided in the constructor will be used.
*	@return Returns the key as an <code>object</code>.
*/
lsm.getObject(keyName);

What's up with version param/property?

The idea of having a version property in your data object is to make it overwrite a similar object saved in the client browser avoiding an outdated object f*@k around with your code. So if the keyName parameter matches a key in the localStorage it will overwrite that mofo. If you put anything as the version it tries to compare with the version property (if existent) in the localStorage.

Beta…ish

This is a working in progress and for sure there are improvements to be made.

localstoragemanager's People

Stargazers

 avatar

Watchers

 avatar  avatar

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.