-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathNote.ts
85 lines (67 loc) · 1.89 KB
/
Note.ts
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
82
83
84
85
export default class Note {
name: string;
back: string;
tags: string[];
cloze = false;
number = 0;
enableInput = false;
answer = '';
media: string[] = [];
notionId?: string;
notionLink?: string;
constructor(name: string, back: string) {
this.name = name;
this.back = back;
this.tags = [];
}
hasCherry() {
const cherry = '🍒';
return (
(this.name && (this.name.includes(cherry) || this.name.includes('🍒'))) ||
(this.back && (this.back.includes(cherry) || this.back.includes('🍒')))
);
}
hasAvocado() {
const avocado = '🥑';
return (
(this.name &&
(this.name.includes(avocado) || this.name.includes('🥑'))) ||
(this.back && (this.back.includes(avocado) || this.back.includes('🥑')))
);
}
copyValues(clozeCard: Note) {
this.name = clozeCard.name;
this.back = clozeCard.back;
this.tags = clozeCard.tags;
this.cloze = clozeCard.cloze;
this.number = clozeCard.number;
this.enableInput = clozeCard.enableInput;
this.answer = clozeCard.answer;
this.media = clozeCard.media;
this.notionId = clozeCard.notionId;
this.notionLink = clozeCard.notionLink;
}
hasRefreshIcon() {
return this.name.includes('🔄') || this.name.includes('🔄');
}
reversed(input: Note): Note {
const note = new Note(input.back, input.name);
note.tags = input.tags;
note.media = input.media;
// Due to backwards compatability, do not increment number here
note.number = -1;
return note;
}
isValidBasicNote(): boolean {
if (!this.name || !this.back) {
return false;
}
return this.name.trim().length > 0 && this.back.trim().length > 0;
}
isValidClozeNote() {
return this.cloze && this.name && this.name.trim();
}
isValidInputNote() {
return this.enableInput && this.name && this.answer && this.answer.trim();
}
}