Checking for types of objects in my script?
<p>I'm writing a localStorage wrapper to make inserting and retrieving data easier when needing it to do more robust queries.</p>

<p>My script is here:
<a href="https://github.com/OscarGodson/storageLocker" rel="nofollow">https://github.com/OscarGodson/storageLocker</a></p>

<p>A user of my script asked me how he could save a Date and i told him the proper procedure (save <code>new Date().getTime()</code> to the JSON and revive it with something like <code>new Date(json.time)</code> but he was trying to do <code>hisStorage.save({'the_date':new Date()})</code>, but to his surprise when he went to get the data it'd be malformed.</p>

<p>So, my question is, how can I catch inserts like this and other objects (maybe events?), convert them for the users to be stored in the JSON and also retrieved properly? I've been working on it all day and i can't figure out how to check for certain types of objects and convert accordingly via some switch case.</p>

<p>The save and retrieve part of my script looks like this:</p>

<p><strong>Saving Data:</strong></p>

<pre><code>storageLocker.prototype.save = function(value){
    var json = JSON.parse(localStorage.getItem(this.catalog));
    if(json == null){json = {};}
    for(var key in value){
        if(value.hasOwnProperty(key)){
            json[key] = value[key];
        }
    }
    localStorage.setItem(this.catalog,JSON.stringify(json));
    return this;
}
</code></pre>

<p><strong>Getting Data:</strong></p>

<pre><code>storageLocker.prototype.get = function(value){
    json = JSON.parse(localStorage.getItem(this.catalog));
    if(json == null){json = {};}
    if(value){
        if(typeof json[value] !== 'undefined'){
            return json[value];
        }
        else{
            //Makes it so you can check with myStorage.get('thisWontExist').length
            //and it will return 0 and typeof will return object.
            return new Object('');
        }
    }
    else{
        return json;
    }
};
</code></pre>
