-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (67 loc) · 1.26 KB
/
index.js
File metadata and controls
81 lines (67 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Module dependencies.
*/
var noop = function(){};
/**
* Cycles collected.
*/
var cycles = [];
/**
* Expose `Cycle`.
*/
exports = module.exports = Cycle;
/**
* Return collected cycles and reset.
*
* @return {Array}
* @api public
*/
exports.flush = function(){
var flushed = cycles;
cycles = [];
return flushed;
};
/**
* Initialize a new Cycle with the given `id` and `name`.
*
* @param {String} name
* @param {String|Number} id
* @api public
*/
function Cycle(name, id) {
if (!(this instanceof Cycle)) return new Cycle(name, id);
if ('string' != typeof name) throw new TypeError('cycle name required');
if (null == id) throw new TypeError('id required');
this.name = name;
this.id = id;
}
/**
* Trace start of `type` with `date`.
*
* @param {String} type
* @param {Number|Date} [date]
* @api public
*/
Cycle.prototype.start = function(type, date){
cycles.push({
id: this.id,
cycle: this.name,
type: type,
start: +(date || new Date)
});
};
/**
* Trace end of `type` with `date`.
*
* @param {String} type
* @param {Number|Date} [date]
* @api public
*/
Cycle.prototype.end = function(type, date){
cycles.push({
id: this.id,
cycle: this.name,
type: type,
end: +(date || new Date)
});
};