mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-20 00:37:26 +00:00
Refactor code by suggestion to use RegExp and add tests coverage
This commit is contained in:
committed by
Rob Harrington
parent
7a07e8fa16
commit
a1ffc869f3
@@ -10,7 +10,5 @@ Darkswarm.factory "Matcher", ->
|
||||
# Return true if text occurs at the beginning of any word present in an array of strings
|
||||
matchBeginning: (properties, text) ->
|
||||
text = text.trim()
|
||||
properties.some (prop) ->
|
||||
prop ||= ""
|
||||
prop.split(' ').some (word) ->
|
||||
word.toLowerCase().indexOf(text.toLowerCase()) == 0
|
||||
regexp = new RegExp("(?:^|[\\s-])#{text}", "i")
|
||||
properties.some (prop) -> (prop || "").search(regexp) >= 0
|
||||
|
||||
Reference in New Issue
Block a user