GithubHelp home page GithubHelp logo

andrewpage / clientstore.js Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 397 KB

Browser agnostic interface to client side storage.

Home Page: http://andrewpage.github.io/clientstore.js

License: MIT License

JavaScript 100.00%

clientstore.js's Introduction

ClientStore.js

ClientStore.js is a JavaScript shim/library that provides a browser-support agnostic interface to both client-side data storage options, WebStorage and Cookies.

Usage

// Instantiate a new ClientStore object
var clientStore = new ClientStore({
    // Pass any options in this parameter
    persistent: true,
    expirationMultiplier: 1000
});

// Use the set() method to set a key and its value
clientStore.set('key', 'This is ClientStore!');

// Pass in a third parameter to define an expiration time.
// Expiration time is defined in milliseconds
clientStore.set('expiringKey', 'This will expire in 5 seconds!', 5000);

// Use the get() method to retrieve a value for a given key
var value = clientStore.get('key'); // value = This is ClientStore!

// Call expire() to check all WebStorage entries, and clean out the ones that have expired. expire() is automatically called on page load.
clientStore.expire();

The same syntax (set and get) applies to both WebStorage and Cookie based client-side storage, with or without an expiration time.

Options

There are a number of configuration options that you can pass to ClientStore. The options parameter is an Object, and each of these options is a key on that Object.

Name Type Description
persistent Boolean Determines whether LocalStorage (true value) or SessionStorage (false value) will be used if WebStorage is available.
forceCookies Boolean Force usage of Cookie storage and completely bypass any WebStorage compatibility checks.
expirationMultiplier Integer Any value passed to set() as the expiration time will be multiplied by this multiplier. e.g. 1000 if you would like to specify expiration time in seconds, 86400000 if you would like to specify expiration time in days.

Documentation

You can read full documentation on the ClientStore.js library here.

Contributing

See the contributing file for information on making contributions to ClientStore.js. Email me at andrew (at) andrewpage (dot) me if you have any questions.

clientstore.js's People

Contributors

andrewpage avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.