Skip to content

Commit 29608f5

Browse files
committed
Return the GitStats object.
1 parent 802bfec commit 29608f5

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

lib/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var GitStats = module.exports = {};
4242
* - `hash` (String): The commit hash.
4343
*
4444
* @param {Function} callback The callback function.
45-
* @return {undefined}
45+
* @return {GitStats} The `GitStats` object.
4646
*/
4747
GitStats.record = function (data, callback) {
4848

@@ -54,15 +54,18 @@ GitStats.record = function (data, callback) {
5454
}
5555

5656
if (!data.date || !/^Moment|Date$/.test(data.date.constructor.name)) {
57-
return callback(new Error("The date field should be a string or a date object."));
57+
callback(new Error("The date field should be a string or a date object."));
58+
return GitStats;
5859
}
5960

6061
if (typeof data.hash !== "string" || !data.hash) {
61-
return callback(new Error("Invalid hash."));
62+
callback(new Error("Invalid hash."));
63+
return GitStats;
6264
}
6365

6466
if (typeof data.url !== "string" || !data.url) {
65-
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."));
67+
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."));
68+
return GitStats;
6669
}
6770

6871
// Get stats
@@ -77,6 +80,8 @@ GitStats.record = function (data, callback) {
7780

7881
GitStats.save(stats, callback);
7982
});
83+
84+
return GitStats;
8085
};
8186

8287
/**
@@ -86,7 +91,7 @@ GitStats.record = function (data, callback) {
8691
* @name get
8792
* @function
8893
* @param {Function} callback The callback function.
89-
* @return {undefined}
94+
* @return {GitStats} The `GitStats` object.
9095
*/
9196
GitStats.get = function (callback) {
9297
Fs.readFile(STORE_PATH, "utf-8", function (err, data) {
@@ -98,6 +103,7 @@ GitStats.get = function (callback) {
98103
}
99104
callback(null, data);
100105
});
106+
return GitStats;
101107
};
102108

103109
/**
@@ -108,10 +114,11 @@ GitStats.get = function (callback) {
108114
* @function
109115
* @param {Object} stats The stats to be saved.
110116
* @param {Function} callback The callback function.
111-
* @return {undefined}
117+
* @return {GitStats} The `GitStats` object.
112118
*/
113119
GitStats.save = function (stats, callback) {
114120
Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback);
121+
return GitStats;
115122
};
116123

117124
/**
@@ -127,7 +134,7 @@ GitStats.save = function (stats, callback) {
127134
* - `format` (String): The format of the date (default: `"MMM D, YYYY"`).
128135
*
129136
* @param {Function} callback The callback function called with the current day formatted (type: string) and the `Moment` date object.
130-
* @return {undefined}
137+
* @return {GitStats} The `GitStats` object.
131138
*/
132139
GitStats.iterateDays = function (data, callback) {
133140

@@ -155,6 +162,8 @@ GitStats.iterateDays = function (data, callback) {
155162
callback(cDay, start);
156163
start.add(1, "days");
157164
}
165+
166+
return GitStats;
158167
};
159168

160169
/**
@@ -165,7 +174,7 @@ GitStats.iterateDays = function (data, callback) {
165174
* @function
166175
* @param {Object} data The object passed to the `iterateDays` method.
167176
* @param {Function} callback The callback function.
168-
* @return {undefined}
177+
* @return {GitStats} The `GitStats` object.
169178
*/
170179
GitStats.graph = function (data, callback) {
171180

@@ -196,6 +205,8 @@ GitStats.graph = function (data, callback) {
196205

197206
callback(null, year);
198207
});
208+
209+
return GitStats;
199210
};
200211

201212
/**
@@ -206,7 +217,7 @@ GitStats.graph = function (data, callback) {
206217
* @function
207218
* @param {Object} data The object passed to the `graph` method.
208219
* @param {Function} callback The callback function.
209-
* @return {undefined}
220+
* @return {GitStats} The `GitStats` object.
210221
*/
211222
GitStats.calendar = function (data, callback) {
212223
GitStats.graph(data, function (err, graph) {
@@ -248,6 +259,7 @@ GitStats.calendar = function (data, callback) {
248259

249260
callback(null, cal);
250261
});
262+
return GitStats;
251263
};
252264

253265
/**
@@ -258,7 +270,7 @@ GitStats.calendar = function (data, callback) {
258270
* @function
259271
* @param {Object} data The object passed to the `calendar` method.
260272
* @param {Function} callback The callback function.
261-
* @return {undefined}
273+
* @return {GitStats} The `GitStats` object.
262274
*/
263275
GitStats.ansiCalendar = function (data, callback) {
264276

@@ -352,4 +364,6 @@ GitStats.ansiCalendar = function (data, callback) {
352364

353365
callback(null, strYear);
354366
});
367+
368+
return GitStats;
355369
};

0 commit comments

Comments
 (0)