forked from jmhobbs/jsTodoTxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsTodoExtensions.js
56 lines (49 loc) · 1.5 KB
/
jsTodoExtensions.js
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
/*!
Extensions to the todo.txt format
*/
function TodoTxtExtension( name ) {
this.reset = function () {
this.name = null;
this.parsingFunction = null;
};
// The parsing function should return an array containing
// the real value of the element, the parsed task line and
// the string representation of the value.
this.parsingFunction = function ( line ) {
return [null, null, null];
};
}
function HiddenExtension() {
this.name = "h";
}
HiddenExtension.prototype = new TodoTxtExtension();
HiddenExtension.prototype.parsingFunction = function(line) {
var hidden = null;
var hiddenRegex = /\bh:1\b/;
var matchHidden = hiddenRegex.exec( line );
if ( matchHidden !== null ) {
hidden = true;
}
return [hidden, line.replace(hiddenRegex, ''), hidden ? '1' : null];
};
function DueExtension() {
this.name = "due";
}
DueExtension.prototype = new TodoTxtExtension();
DueExtension.prototype.parsingFunction = function(line) {
var dueDate = null;
var dueRegex = /due:([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})\s*/;
var matchDue = dueRegex.exec(line);
if ( matchDue !== null ) {
var datePieces = matchDue[1].split('-');
dueDate = new Date( datePieces[0], datePieces[1] - 1, datePieces[2] );
return [dueDate, line.replace(dueRegex, ''), matchDue[1]];
}
return [null, null, null];
};
// Exported functions for node
(function(exports){
exports.TodoTxtExtension = TodoTxtExtension;
exports.HiddenExtension = HiddenExtension;
exports.DueExtension = DueExtension;
})(typeof exports === 'undefined' ? window : exports);