aboutsummaryrefslogtreecommitdiff
path: root/src/pattern.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pattern.js')
-rw-r--r--src/pattern.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/pattern.js b/src/pattern.js
new file mode 100644
index 0000000..ad94253
--- /dev/null
+++ b/src/pattern.js
@@ -0,0 +1,24 @@
+export class Pattern {
+ constructor(id, isRegex, value, label) {
+ this.id = id;
+ this.isRegex = isRegex;
+ this.value = value;
+ this.label = label;
+ }
+
+ get regex() { return new RegExp(this.isRegex ? this.value : `^${this.value}$`); }
+ get isEmpty() { return this.label === null; }
+ static emptyPattern = () => new Pattern(0, true, '', null);
+ static anyPattern = () => new Pattern('any', true, '.*', 'Any');
+}
+
+export class PatternEntry {
+ constructor(name, idx, calPattern, eventPattern) {
+ this.name = name;
+ this.idx = idx;
+ this.cal = calPattern;
+ this.event = eventPattern;
+ }
+
+ static defaultPatternEntry = (idx) => new PatternEntry('', idx, Pattern.emptyPattern(), Pattern.anyPattern());
+}