Coder Social home page Coder Social logo

lockr's Introduction

Lockr logo

A minimal API wrapper for localStorage. Simple as your high-school locker.

Lockr (it's pronounced /ˈlɒkəʳ/) is a extremely lightweight library (<1kb when minified), designed to facilitate how you interact with localStorage. Saving objects and arrays, numbers or other data types, accessible via a Redis-like API, heavily inspired by node_redis.

How to use lockr

In order to user lockr, you firstly need to install it in your project.

bower install lockr

or download it manually from here and hook it in your HTML.

<script src="/path/to/lockr.js" type="text/javascript"></script>

API reference

Lockr.set - arguments: [ key, value ]

Set a key to a particular value. Value could be String or Number. Do not use this for saving Object or Array.

Example

Lockr.set('username', 'Coyote'); // Saved as string
Lockr.set('user_id', 12345); // Saved as number

Lockr.hset - arguments: [ hash_key, hash_value ]

Save a hash object (Object or Array) under a hash key.

Example

Lockr.hset('users', [{name: 'John Doe', age: 18}, {name: 'Jane Doe', age: 19}]);

Lockr.get - arguments: [ key or hash_key ]

Returns the saved value for given key, even if the saved value is hash object.

Example

Lockr.get('username');
> "Coyote"

Lockr.get('user_id');
> 12345

Lockr.get('users');
>  [{name: 'John Doe', age: 18}, {name: 'Jane Doe', age: 19}]

Lockr.getAll - arguments: null

Returns all saved values & objects, in an Array

Example

Lockr.getAll();
> ["Coyote", 12345, [{name: 'John Doe', age: 18}, {name: 'Jane Doe', age: 19}]]

Lockr.flush() - arguments: null

Empties localStorage().

Example

localStorage.length;
> 3
Lockr.flush();
localStorage.length;
> 0

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.