-
Notifications
You must be signed in to change notification settings - Fork 21
Capability to match strings within an array #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,12 +80,37 @@ | |
| */ | ||
| function testForField(item, pattern, address) { | ||
| const value = resolveAddress(item, address); | ||
| const found = typeof value === 'string' ? | ||
| !!value.match(new RegExp(pattern, uiTreeFilterSettings.regexFlags)) : | ||
| false; | ||
| let found; | ||
| if (typeof value === 'string') { | ||
| found = !!value.match(new RegExp(pattern, uiTreeFilterSettings.regexFlags)); | ||
| } else if (Array.isArray(value)) { | ||
| found = searchStringInArray(new RegExp(pattern, uiTreeFilterSettings.regexFlags), value); | ||
| } else { | ||
| found = false; | ||
| } | ||
| return found || visit(item[uiTreeFilterSettings.descendantCollection], pattern, address); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if pattern matches any of the strings in an array | ||
| * | ||
| * @param {string} str | ||
| * @param {array} strArray | ||
| * | ||
| * @returns {boolean} | ||
| */ | ||
| function searchStringInArray(str, strArray) { | ||
| let found = false; | ||
| if (strArray) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this check does not seem to be necessary: this function is only used in a context where the 2nd argument is pre-ensured to be an array. |
||
| strArray.forEach(function (item) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lalooola please use Array#some here. This will improve performance of large arrays. |
||
| if (item.match(str)) { | ||
| found = true; | ||
| } | ||
| }); | ||
| return found; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Checks if pattern matches any of addresses | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please declare explicitly that
strArrayhas to be an array of strings:string[]or (preferably)Array.<string>.Otherwise the function does not do what it claims to do