Skip to content

Commit 8f2adaa

Browse files
author
Elizeu Santos
committed
Implements getFlag method
1 parent a721e62 commit 8f2adaa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ui/src/lib/RegexBuilder.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { REGEX_FLAGS } from '../constants';
1+
import { REGEX_FLAGS } from "../constants";
22

33
export default class RegexBuilder {
44
constructor(rawData) {
55
const data = (() => {
6-
if (typeof rawData === 'string') {
6+
if (typeof rawData === "string") {
77
const decoded = decodeURIComponent(atob(rawData));
88
return JSON.parse(decoded);
9-
} else if (typeof rawData === 'object' && rawData !== null) {
9+
} else if (typeof rawData === "object" && rawData !== null) {
1010
return rawData;
1111
}
1212
return {};
@@ -15,7 +15,7 @@ export default class RegexBuilder {
1515
this.flags = {};
1616
this.source = data.regex || null;
1717
this.testString = data.test_string || null;
18-
this.matchType = data.match_type || 'match';
18+
this.matchType = data.match_type || "match";
1919
this.setFlags(data.flags);
2020
}
2121

@@ -24,7 +24,7 @@ export default class RegexBuilder {
2424
regex: this.source,
2525
flags: this.getFlag(),
2626
match_type: this.matchType,
27-
test_string: this.testString,
27+
test_string: this.testString
2828
};
2929
}
3030

@@ -39,11 +39,15 @@ export default class RegexBuilder {
3939
.reduce(
4040
(acc, [key, value]) => ({
4141
...acc,
42-
[key]: false,
42+
[key]: false
4343
}),
4444
{}
4545
);
4646
}
4747

48-
getFlag() {}
48+
getFlag() {
49+
return Object.keys(this.flags)
50+
.filter(key => this.flags[key])
51+
.reduce((acc, cValue) => acc | REGEX_FLAGS[cValue], 0);
52+
}
4953
}

0 commit comments

Comments
 (0)