From 6858de4ff5f7212d2fb1168a75539c9aa5a078d6 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 30 Nov 2018 11:15:15 -0500 Subject: [PATCH] refactor(@embark/console): refactor duplicated fuzzy search into a single private method --- src/lib/modules/console/suggestions.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/modules/console/suggestions.ts b/src/lib/modules/console/suggestions.ts index 16189ab95..d6ae390b4 100644 --- a/src/lib/modules/console/suggestions.ts +++ b/src/lib/modules/console/suggestions.ts @@ -76,7 +76,7 @@ export default class Suggestions { suggestions.push({value: "EmbarkJS", command_type: "javascript object", description: "EmbarkJS static functions for Storage, Messages, Names, etc."}); if (cmd.indexOf(".") <= 0) { - return cb(fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original)); + return cb(this.searchSuggestions(cmd, suggestions)); } try { @@ -92,11 +92,15 @@ export default class Suggestions { } catch (e) { } - return cb(fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original)); + return cb(this.searchSuggestions(cmd, suggestions)); }, false, true); } catch (e) { } - return cb(fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original)); + return cb(this.searchSuggestions(cmd, suggestions)); + } + + private searchSuggestions(cmd: string, suggestions: SuggestionsList) { + return fuzzySearch(cmd, suggestions, (suggestion: Suggestion) => suggestion.value + " " + suggestion.description).map((x: any) => x.original); } }