-
Notifications
You must be signed in to change notification settings - Fork 0
/
addTask.js
62 lines (56 loc) · 1.41 KB
/
addTask.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
const dataStore = require('./dataStore');
const defaultTaskProps = require('./defaultTaskProps');
const prompt = require('prompt');
let tasks = require('./tasks.json');
prompt.start();
const onErr = (err) => {
console.log(err);
return 1;
};
const properties = [
{
name: 'title',
validator: /^[a-zA-Zа-яА-Я\s\-]+$/,
warning: 'Title must be only letters, spaces, or dashes'
},
{
name: 'message',
},
{
name: 'hours',
validator: /2[0-3]|1[0-9]|0[0-9]|[^0-9][0-9]/,
warning: 'Hours must be only two integers, e.g. 18'
},
{
name: 'minutes',
validator: /[0-5][0-9]/,
warning: 'Minutes must be only two integers, e.g. 18'
},
{
name: 'seconds',
validator: /[0-5][0-9]/,
warning: 'Seconds must be only two integers, e.g. 18'
},
];
prompt.get(properties, (err, result) => {
if (err) { return onErr(err); }
console.log('Task data received');
console.log('Title: ' + result.title);
console.log('Message: ' + result.message);
console.log('Time: ' + result.hours + ":" + result.minutes + ":" + result.seconds);
const newTask = {
time: {
hours: result.hours,
minutes: result.minutes,
seconds: result.seconds
},
props: {
'title': result.title,
'message': result.message,
'icon': defaultTaskProps.icon,
'wait': defaultTaskProps.wait
}
};
tasks[result.title] = newTask;
dataStore(tasks);
});