From 7327707851cb0cc82001781571c2d7b6fedf7ffa Mon Sep 17 00:00:00 2001 From: Rohit Chakraborty Date: Mon, 20 Apr 2020 19:08:31 +0530 Subject: [PATCH] Fixes issue #144 - Ignore Case on Search 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. --- README.md | 6 +++--- src/flamegraph.js | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 581a126..cffa61d 100644 --- a/README.md +++ b/README.md @@ -306,11 +306,11 @@ If called with no arguments, `setColorMapper` will reset the color hash function # flamegraph.setSearchMatch([function]) -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; }) diff --git a/src/flamegraph.js b/src/flamegraph.js index 9000fb3..3de198e 100644 --- a/src/flamegraph.js +++ b/src/flamegraph.js @@ -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