Skip to content
local and sessionStorage with (nested) objects, DEPENDS ON Object.observe()
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


ObjectStorage wraps a magic Storage object (i.e. localStorage and sessionStorage) to make it accessible and writable like a normal objects. Meaning it can contain objects and arrays and scalars, and it will be stored in the parent storage object (i.e. localStorage).

There are 2 ways of wrapping Storage data:

Per property

var prop = ObjectStorage(localStorage, 'prop'); = 'data';
prop.more = {data: 'is possible'};
prop.there = ['limit', 'on' nesting'];
prop.there[0] = 'NO LIMIT';
console.log(localStorage.prop); // JSON for `prop`

This is very verbose if you need several properties.

Copying part of Storage

var storage = ObjectStorage(localStorage, ['prop', 'more', 'props']); = 'data'; = {more; 'data'};
storage.props.type = 'object';

Only mentioned properties will exist in storage and making new ones won't work. Every property will be an object. It can contain arrays, but can't be an array itself (yet: #2).

You can’t perform that action at this time.