This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +1
-23
lines changed Expand file tree Collapse file tree 3 files changed +1
-23
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ interface IOptions<T extends {}> {
2323 keys : Array < string | keyof T > ;
2424 funcs ?: Array < ( T ) => string > ;
2525 shouldMatchWordsOnly ?: boolean ;
26- shouldMatchPrefix ?: boolean ;
2726 // whether to apply unhomoglyph and strip diacritics to fuzz up the search. Defaults to true
2827 fuzzy ?: boolean ;
2928}
@@ -56,12 +55,6 @@ export default class QueryMatcher<T extends Object> {
5655 if ( this . _options . shouldMatchWordsOnly === undefined ) {
5756 this . _options . shouldMatchWordsOnly = true ;
5857 }
59-
60- // By default, match anywhere in the string being searched. If enabled, only return
61- // matches that are prefixed with the query.
62- if ( this . _options . shouldMatchPrefix === undefined ) {
63- this . _options . shouldMatchPrefix = false ;
64- }
6558 }
6659
6760 setObjects ( objects : T [ ] ) {
@@ -112,7 +105,7 @@ export default class QueryMatcher<T extends Object> {
112105 resultKey = resultKey . replace ( / [ ^ \w ] / g, '' ) ;
113106 }
114107 const index = resultKey . indexOf ( query ) ;
115- if ( index !== - 1 && ( ! this . _options . shouldMatchPrefix || index === 0 ) ) {
108+ if ( index !== - 1 ) {
116109 matches . push (
117110 ...candidates . map ( ( candidate ) => ( { index, ...candidate } ) ) ,
118111 ) ;
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ export default class UserProvider extends AutocompleteProvider {
5656 this . matcher = new QueryMatcher ( [ ] , {
5757 keys : [ 'name' ] ,
5858 funcs : [ obj => obj . userId . slice ( 1 ) ] , // index by user id minus the leading '@'
59- shouldMatchPrefix : true ,
6059 shouldMatchWordsOnly : false ,
6160 } ) ;
6261
Original file line number Diff line number Diff line change @@ -183,18 +183,4 @@ describe('QueryMatcher', function() {
183183 expect ( results . length ) . toBe ( 1 ) ;
184184 expect ( results [ 0 ] . name ) . toBe ( 'bob' ) ;
185185 } ) ;
186-
187- it ( 'Matches only by prefix with shouldMatchPrefix on' , function ( ) {
188- const qm = new QueryMatcher ( [
189- { name : "Victoria" } ,
190- { name : "Tori" } ,
191- ] , {
192- keys : [ "name" ] ,
193- shouldMatchPrefix : true ,
194- } ) ;
195-
196- const results = qm . match ( 'tori' ) ;
197- expect ( results . length ) . toBe ( 1 ) ;
198- expect ( results [ 0 ] . name ) . toBe ( 'Tori' ) ;
199- } ) ;
200186} ) ;
You can’t perform that action at this time.
0 commit comments