Skip to content

Commit

Permalink
Fixes issue spiermar#144 - Ignore Case on Search
Browse files Browse the repository at this point in the history
Add an optional boolean argument for the function searchMatch. If the argument is true, then only the search will be case-sensitive. By default if no argument is passed during the function call, the argument will be set to false.
  • Loading branch information
rohchakr committed Apr 20, 2020
1 parent c817cf3 commit 7327707
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ If called with no arguments, `setColorMapper` will reset the color hash function

<a name="setSearchMatch" href="#setSearchMatch">#</a> flamegraph.<b>setSearchMatch</b>(<i>[function]</i>)

Replaces the built-in node search match function. Function takes two arguments,
the node data structure and the search term. It must return a boolean. Example:
Replaces the built-in node search match function. Function takes three arguments,
the node data structure, the search term and an optional boolean argument for case-sensitive search. If the third argument is not provided, the search will not be case-sensitive. It must return a boolean. Example:

```js
flamegraph.setSearchMatch(function(d, term) {
flamegraph.setSearchMatch(function(d, term, true) {
// Non-regex implementation of the search function
return d.data.name.indexOf(term) != 0;
})
Expand Down
8 changes: 6 additions & 2 deletions src/flamegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ export default function () {
}
var originalSearchHandler = searchHandler

let searchMatch = (d, term) => {
let searchMatch = (d, term, caseSensitive = false) => {
if (!term) {
return false
}
let label = getName(d)
if (!caseSensitive) {
term = term.toLowerCase()
label = label.toLowerCase()
}
const re = new RegExp(term)
const label = getName(d)
return typeof label !== 'undefined' && label && label.match(re)
}
const originalSearchMatch = searchMatch
Expand Down

0 comments on commit 7327707

Please sign in to comment.