Skip to content

Commit

Permalink
Implements getFlag method
Browse files Browse the repository at this point in the history
  • Loading branch information
elizeusdsantos committed Nov 15, 2017
1 parent a721e62 commit 8f2adaa
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ui/src/lib/RegexBuilder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { REGEX_FLAGS } from '../constants';
import { REGEX_FLAGS } from "../constants";

export default class RegexBuilder {
constructor(rawData) {
const data = (() => {
if (typeof rawData === 'string') {
if (typeof rawData === "string") {
const decoded = decodeURIComponent(atob(rawData));
return JSON.parse(decoded);
} else if (typeof rawData === 'object' && rawData !== null) {
} else if (typeof rawData === "object" && rawData !== null) {
return rawData;
}
return {};
Expand All @@ -15,7 +15,7 @@ export default class RegexBuilder {
this.flags = {};
this.source = data.regex || null;
this.testString = data.test_string || null;
this.matchType = data.match_type || 'match';
this.matchType = data.match_type || "match";
this.setFlags(data.flags);
}

Expand All @@ -24,7 +24,7 @@ export default class RegexBuilder {
regex: this.source,
flags: this.getFlag(),
match_type: this.matchType,
test_string: this.testString,
test_string: this.testString
};
}

Expand All @@ -39,11 +39,15 @@ export default class RegexBuilder {
.reduce(
(acc, [key, value]) => ({
...acc,
[key]: false,
[key]: false
}),
{}
);
}

getFlag() {}
getFlag() {
return Object.keys(this.flags)
.filter(key => this.flags[key])
.reduce((acc, cValue) => acc | REGEX_FLAGS[cValue], 0);
}
}

0 comments on commit 8f2adaa

Please sign in to comment.