-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Setting.ts
61 lines (50 loc) · 1.5 KB
/
Setting.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
import { Action } from "./Trello";
export interface Setting {
excludes?: Array<{
charactersOrLess?: number;
match?: string;
}>;
isAddDoneTime?: boolean;
doneListName?: string;
}
export class SettingGuardian {
public setting: Setting;
constructor(setting: Setting = {}) {
this.setting = setting;
}
public isAddDoneTime(listName: string) {
if (this.setting.isAddDoneTime === undefined || !this.setting.isAddDoneTime)
return false;
return listName === (this.setting.doneListName ?? "Done");
}
public isSkipEvent(trelloAction: Action) {
if (this.setting?.excludes === undefined) {
return false;
}
const excludes = this.setting.excludes;
const isCharacterOrLess = (charactersOrLess: number) => {
return charactersOrLess >= trelloAction.data.card.name.length;
};
const isMatch = (match: string) => {
return trelloAction.data.card.name.match(match) !== null;
};
let isSkip = false;
for (const excludeSetting of excludes) {
const checks: boolean[] = [];
if (excludeSetting.charactersOrLess && trelloAction.data.card) {
checks.push(
isCharacterOrLess(excludeSetting.charactersOrLess as number)
);
}
if (excludeSetting.match && trelloAction.data.card) {
checks.push(isMatch(excludeSetting.match as string));
}
if (checks.length === 0) continue;
if (checks.every((isTrue) => isTrue)) {
isSkip = true;
break;
}
}
return isSkip;
}
}