-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathwatson.js
69 lines (53 loc) · 1.83 KB
/
watson.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
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Watson - Collects data for Sherlock to analyze.
* Copyright (c) 2021 Neil Gupta
*
* This is an example Watson file. You can use this as a
* starting point to make any changes for your use case.
*/
var Watson = (function() {
var helpers = {
// Place your helper functions here...
// Validates the parsed times returned by Sherlock
validate: function(Sherlocked) {
if (!Sherlocked.startDate)
return 'Sorry, you\'ve entered an invalid date :(';
if (Sherlocked.endDate && Sherlocked.startDate > Sherlocked.endDate)
return 'Sorry, the end time can\'t be before the start time.';
return true;
},
// Parse the input string to try to figure out which calendar the user wants.
parseCalendar: function(str, Sherlocked) {
// Simple example of searching for CS 104 calendar and removing it from input string
if (str.indexOf('CS 104') !== -1) {
Sherlocked.calendar = 'CS 104';
str = str.replace('CS 104', '');
}
return [str, Sherlocked];
},
};
return {
/*
* Takes the untouched input string, returns
* an array with the modified input string at position 0 and a new Sherlocked object at position 1
*/
preprocess: function(str) {
var Sherlocked = {};
// Manipulate str and Sherlocked here...
return helpers.parseCalendar(str, {});
},
/*
* Takes a Sherlocked object, and returns that Sherlocked object with any desired modifications.
*/
postprocess: function(Sherlocked) {
// Manipulate Sherlocked here...
Sherlocked.validated = helpers.validate(Sherlocked);
return Sherlocked;
},
/* Config vars for disabling certain features */
config: {
// Should Sherlock try to parse time ranges and return an endDate?
disableRanges: false
}
};
})();