03 May 2013


Rook is a ~2kb JavaScript library to assist with localStorage and the DOM.

Github Repo

You can get a great overview of localStorage in this diveintohtml5 article.


rook().view();  // View contents of localStorage in console
rook().wipe(); // Clear localStorage


rook().set(key, obj);  // Set value to key in localStorage


rook().set('foo', 'bar'); // String
rook().set('foo', bar); // Variable
    {"names": [{"firstName":"Joe" , "lastName":"Smith"},   // Object
    {"firstName":"Jan" , "lastName":"Doe"},
    {"firstName":"Bob" , "lastName":"Saget"}]

Set Element

rook(element).setEle(key); // Set text in element to localStorage key




var foo = rook().get(key) // Get value from key in localStorage

Push Element To Array

rook(element).eleToArray('arrayName', limit);  // The limit keeps the user from adding past a certain amount of values


rook('#foo').eleToArray('newArr', 5);  // Push text in DOM element to localStorage array

Import CSV to localStorage

rook(element).upCSV(text, name);  // Import a CSV file into localStorage

Example (using jQuery ready and AJAX):

$(document).ready(function() {  
    $('#clkcsv').click(function() {
            type: "GET",
            url: "example.txt",
            dataType: "text",
            success: function(data) {
                rook('#foo').upCSV(data, 'myCSV');

Order Array

rook().order(arrayName);  // Alphabetical
rook().reverse(arrayName);  // Reverse


Feel free to fork and submit pull requests to add features or fix bugs. There is a lot that could be done better and in addition to what is here, so any help would be appreciated. If you are looking for ways to help check out the Issues, but areas that are especially in need are the following:

  • CSV Parsing and Regex
  • Ordering is only lexicographical. Need other sorting including numerically.

In addition to all the clean up and bug fixing, I would also like to implement more SQL-like functions as well.


Rook is licensed under the MIT License.