Skip to content

magnet-inc/lookie

Repository files navigation

Lookie

Build Status Sauce Test Status

Sauce Test Status

Local storage in anywhere.

Installation

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

Usage

First, setup your lookie storage.

var lookie = new Lookie('namespace');

Get and Set values for key.

lookie.set('foo', anyObject);
lookie.get('foo'); // => anyObject
lookie.del('foo');
lookie.get('foo'); // => null or undefined

Check existence of the key.

lookie.exists('foo'); // => false
lookie.set('foo', 1);
lookie.exists('foo'); // => true

List the keys in a namespace.

lookie.keys(); // => []
lookie.set('foo', 1);
lookie.keys(); // => ['foo']

Clear all values in a namespace.

lookie.set('foo', 1);
lookie.keys(); // => ['foo']
looke.clear();
lookie.keys(); // => []

Event handling

lookie.on('add', function(key, newValue) {
  console.log(key);
});

lookie.on('change', function(key, newValue, oldValue) {
  console.log(key);
});

lookie.on('del', function(key) {
  console.log(key);
});

License

MIT License