Coder Social home page Coder Social logo

persistence's Introduction

Persistence

A small Javascript Library aimed at making it easier to read and write to localstorage

Usage

Instantiate a new Persistence object:
var _p = new Persistence();
To get all data within localStorage for your this instance
var _p = new Persistence();
var allData = _p.getPersistenceStates(); //returns JSON Object of all data
To get a specific value to a key in a key/value pair in local storage
var _p = new Persistence();
var specificData = _p.getPersistenceState('key'); //returns value of that key in the JSON object of all localstorage for this intance
To set persistence data
var _p = new Persistence();
var newData = {foo: "bar"};
var updatedData = _p.setPersistenceState(newData); //updates localstorage and returns JSON Object of all updated data
To clear all localStorage data for a Persistence instance:
var _p = new Persistence();
_p.clearPersistenceStates(); //resets localstorage and deletes all data for that Persistence instance
A Persistence Object instance has an expiration date. By Default it's set to 1 day. To change:
var _p = new Persistence();
_p.setExpirationDays(5); //sets expiration of data to 5 days
To get the current expiration date of a Persistence instance:
var _p = new Persistence();
_p.getExpirationDays(); //returns expiration of data in this instance
A Persistence object uses a key in local storage to set the data, by default its appData. To change:
var _p = new Persistence();
_p.setAppDataKey('newAppKey'); //sets the key in localStorage for this persistence object to "newAppKey"
To get the current key:
var _p = new Persistence();
_p.getAppDataKey(); //sets the key in localStorage for this persistence object to "newAppKey"

persistence's People

Contributors

kobbya avatar

Watchers

James Cloos 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.