// Dependencies
var FsExtra = require("fs-extra")
  , Ul = require("ul")
  ;

const STORE_PATH = Ul.USER_DIR + "/.git-stats";

// Constructor
var GitStats = module.exports = {};

GitStats.record = function (data, callback) {
    FsExtra.readJSON(STORE_PATH, function (err, stats) {
        stats = stats || {};
        var thisRepo = stats[data.url] = Object(stats[data.url]);
        thisRepo[data.hash] = { date: data.date };
        FsExtra.writeJSON(STORE_PATH, stats, callback);
    });
};

GitStats.get = function (data, callback) {
    if (typeof data === "function") {
        callback = data;
        data = {};
    }
    FsExtra.readJSON(STORE_PATH, callback);
};

@@ -66,16 +66,47 @@
 e(%22ul%22)%0A
+  , Moment = require(%22moment%22)%0A
   ;%0A%0Acon
@@ -207,168 +207,1293 @@
 %7D;%0A%0A
-GitStats.record = function (data, callback) %7B%0A    FsExtra.readJSON(STORE_PATH, function (err, stats) %7B%0A        stats = stats %7C%7C %7B%7D;%0A        var thisRepo = stats
+/**%0A * record%0A * Records a new commit.%0A *%0A * @name record%0A * @function%0A * @param %7BObject%7D data The commit data containing:%0A *%0A *  - %60date%60 (String%7CDate): The date object or a string in this format: %60DDD MMM dd HH:mm:ss YYYY%60%0A *  - %60url%60 (String): The repository remote url.%0A *  - %60hash%60 (String): The commit hash.%0A *%0A * @param %7BFunction%7D callback The callback function.%0A * @return %7Bundefined%7D%0A */%0AGitStats.record = function (data, callback) %7B%0A    callback = callback %7C%7C function (err) %7B if (err) throw err; %7D;%0A    data = Object(data);%0A%0A    if (typeof data.date === %22string%22) %7B%0A        data.date = Moment(data.date, %22DDD MMM dd HH:mm:ss YYYY%22);%0A    %7D%0A%0A    if (!data.date %7C%7C data.date.constructor !== Date %7C%7C isNaN(data.date.getTime())) %7B%0A        return callback(new Error(%22The date field should be a string or a date object.%22));%0A    %7D%0A%0A    if (typeof data.hash !== %22string%22 %7C%7C !data.hash) %7B%0A        return callback(new Error(%22Invalid hash.%22));%0A    %7D%0A%0A    if (typeof data.url !== %22string%22 %7C%7C !data.url) %7B%0A        return callback(new Error(%22Invalid url field.%22));%0A    %7D%0A%0A    FsExtra.readJSON(STORE_PATH, function (err, stats) %7B%0A        stats = stats %7C%7C %7B%7D;%0A        var day = data.date.format(%22MMM DDD dd, YYYY%22)%0A          , today = stats%5Bday%5D = Object(stats%5Bday%5D)%0A          , repo = today
 %5Bdat
@@ -1508,21 +1508,21 @@
  Object(
-stats
+today
 %5Bdata.ur
@@ -1524,17 +1524,29 @@
 ta.url%5D)
-;
+%0A          ;%0A
 %0A       
@@ -1550,13 +1550,9 @@
     
-thisR
+r
 epo%5B
@@ -1581,24 +1581,25 @@
 ata.date %7D;%0A
+%0A
         FsEx

Validate data.