From 29608f50c46efba727efd4cafe4f24c169bec10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Mon, 9 Feb 2015 15:11:47 +0200 Subject: [PATCH] Return the GitStats object. --- lib/index.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index b9688da..de8e210 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,7 +42,7 @@ var GitStats = module.exports = {}; * - `hash` (String): The commit hash. * * @param {Function} callback The callback function. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.record = function (data, callback) { @@ -54,15 +54,18 @@ GitStats.record = function (data, callback) { } if (!data.date || !/^Moment|Date$/.test(data.date.constructor.name)) { - return callback(new Error("The date field should be a string or a date object.")); + callback(new Error("The date field should be a string or a date object.")); + return GitStats; } if (typeof data.hash !== "string" || !data.hash) { - return callback(new Error("Invalid hash.")); + callback(new Error("Invalid hash.")); + return GitStats; } if (typeof data.url !== "string" || !data.url) { - return callback(new Error("Invalid url field. This commit is not recorded into the git-stats history since you didn't added the remote url. You can import the previous commits using the git-stats-importer tool.")); + callback(new Error("Invalid url field. This commit is not recorded into the git-stats history since you didn't added the remote url. You can import the previous commits using the git-stats-importer tool.")); + return GitStats; } // Get stats @@ -77,6 +80,8 @@ GitStats.record = function (data, callback) { GitStats.save(stats, callback); }); + + return GitStats; }; /** @@ -86,7 +91,7 @@ GitStats.record = function (data, callback) { * @name get * @function * @param {Function} callback The callback function. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.get = function (callback) { Fs.readFile(STORE_PATH, "utf-8", function (err, data) { @@ -98,6 +103,7 @@ GitStats.get = function (callback) { } callback(null, data); }); + return GitStats; }; /** @@ -108,10 +114,11 @@ GitStats.get = function (callback) { * @function * @param {Object} stats The stats to be saved. * @param {Function} callback The callback function. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.save = function (stats, callback) { Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback); + return GitStats; }; /** @@ -127,7 +134,7 @@ GitStats.save = function (stats, callback) { * - `format` (String): The format of the date (default: `"MMM D, YYYY"`). * * @param {Function} callback The callback function called with the current day formatted (type: string) and the `Moment` date object. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.iterateDays = function (data, callback) { @@ -155,6 +162,8 @@ GitStats.iterateDays = function (data, callback) { callback(cDay, start); start.add(1, "days"); } + + return GitStats; }; /** @@ -165,7 +174,7 @@ GitStats.iterateDays = function (data, callback) { * @function * @param {Object} data The object passed to the `iterateDays` method. * @param {Function} callback The callback function. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.graph = function (data, callback) { @@ -196,6 +205,8 @@ GitStats.graph = function (data, callback) { callback(null, year); }); + + return GitStats; }; /** @@ -206,7 +217,7 @@ GitStats.graph = function (data, callback) { * @function * @param {Object} data The object passed to the `graph` method. * @param {Function} callback The callback function. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.calendar = function (data, callback) { GitStats.graph(data, function (err, graph) { @@ -248,6 +259,7 @@ GitStats.calendar = function (data, callback) { callback(null, cal); }); + return GitStats; }; /** @@ -258,7 +270,7 @@ GitStats.calendar = function (data, callback) { * @function * @param {Object} data The object passed to the `calendar` method. * @param {Function} callback The callback function. - * @return {undefined} + * @return {GitStats} The `GitStats` object. */ GitStats.ansiCalendar = function (data, callback) { @@ -352,4 +364,6 @@ GitStats.ansiCalendar = function (data, callback) { callback(null, strYear); }); + + return GitStats; };