DotStorage

by Farbdose

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>
<script src="https://rawgit.com/Farbdose/DotStorage/master/DotStorage.js"></script>

JavaScript

// Note: actual ability to preserve saved values persistently is not tested

// Test simple strings via dot
dotStorage.Hello = "World";
console.assert(dotStorage.Hello == "World");

// Test simple strings via bracket
dotStorage["Hello"] = "World";
console.assert(dotStorage["Hello"] == "World");

// Test simple objects
dotStorage.simpleObj = {
    "Hello": "World"
};
console.assert(dotStorage.simpleObj.Hello == "World");

// Test array of primitives
input = [1, 2, 3];
dotStorage.arrayTest = input;
dotStorage.arrayTest.forEach(function (e, i) {
    console.assert(input[i] == e)
});

// Test array of objects
dotStorage.complexArrayTest = [
    {"Hello": "World0", "index": 0},
    {"Hello": "World1", "index": 1},
    {"Hello": "World2", "index": 2}
];
dotStorage.complexArrayTest.forEach(function (e, i) {
    console.assert(e.Hello == "World" + i);
    console.assert(e.index == i)
});

// Test DeepProxy (changes to nested attributes are expected to be save in the localStorage too)
var myObj = {"New": "object"};
dotStorage.refTest = myObj;
myObj = dotStorage.refTest;

myObj.New = {"nested": {"otherObject": [0, 1]}};
console.assert(myObj.New.nested.otherObject.length == 2);

myObj.New.nested = 2;
console.assert(myObj.New.nested == 2);


// stresstest
var randomJSON = [
    {
        "_id": "58d2c025a17fd30495034a78",
        "index": 0,
        "guid": "74a90953-ad1c-449b-b368-684bd0e04367",
        "isActive": false,
        "balance": "$1,821.13",
        "picture": "http://placehold.it/32x32",
        "age": 33,
        "eyeColor": "blue",
        "name": {
            "first": "Anne",
            "last": "Allen"
        },
        "company": "BRAINQUIL",
        "email": "anne.allen@brainquil.me",
        "phone": "+1 (920) 423-2627",
        "address": "418 Apollo Street, Staples, South Dakota, 3939",
        "about": "Ut enim voluptate id reprehenderit culpa esse esse proident in anim mollit mollit. Non tempor fugiat sit occaecat id. Fugiat cupidatat pariatur ad...