File tree Expand file tree Collapse file tree 5 files changed +85
-21
lines changed Expand file tree Collapse file tree 5 files changed +85
-21
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const cmp = new Intl.Collator('en').compare;
13
13
14
14
const inf = Infinity ;
15
15
16
- const NEGS_RE = / (?: \s | ^ ) - [ a - z \d ] + / ig;
16
+ const NEGS_RE = / (?: \s + | ^ ) - [ a - z \d ] + / ig;
17
17
18
18
const OPTS = {
19
19
// term segmentation & punct/whitespace merging
@@ -630,10 +630,28 @@ function uFuzzy(opts) {
630
630
631
631
needle = needle . replace ( NEGS_RE , m => {
632
632
negs . push ( m . trim ( ) . slice ( 1 ) ) ;
633
- return ' ' ;
633
+ return '' ;
634
634
} ) ;
635
635
636
+ let negsRe ;
637
+
638
+ if ( negs . length > 0 ) {
639
+ negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
640
+
641
+ if ( needle . trim ( ) == '' ) {
642
+ let idxs = [ ] ;
643
+
644
+ for ( let i = 0 ; i < haystack . length ; i ++ ) {
645
+ if ( ! negsRe . test ( haystack [ i ] ) )
646
+ idxs . push ( i ) ;
647
+ }
648
+
649
+ return [ idxs , null , null ] ;
650
+ }
651
+ }
652
+
636
653
// console.log(negs);
654
+ // console.log(needle);
637
655
638
656
if ( outOfOrder ) {
639
657
// since uFuzzy is an AND-based search, we can iteratively pre-reduce the haystack by searching
@@ -691,10 +709,8 @@ function uFuzzy(opts) {
691
709
let retInfo = null ;
692
710
let retOrder = null ;
693
711
694
- if ( negs . length > 0 ) {
695
- let negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
712
+ if ( negs . length > 0 )
696
713
matches = matches . map ( idxs => idxs . filter ( idx => ! negsRe . test ( haystack [ idx ] ) ) ) ;
697
- }
698
714
699
715
let matchCount = matches . reduce ( ( acc , idxs ) => acc + idxs . length , 0 ) ;
700
716
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const cmp = new Intl.Collator('en').compare;
11
11
12
12
const inf = Infinity ;
13
13
14
- const NEGS_RE = / (?: \s | ^ ) - [ a - z \d ] + / ig;
14
+ const NEGS_RE = / (?: \s + | ^ ) - [ a - z \d ] + / ig;
15
15
16
16
const OPTS = {
17
17
// term segmentation & punct/whitespace merging
@@ -628,10 +628,28 @@ function uFuzzy(opts) {
628
628
629
629
needle = needle . replace ( NEGS_RE , m => {
630
630
negs . push ( m . trim ( ) . slice ( 1 ) ) ;
631
- return ' ' ;
631
+ return '' ;
632
632
} ) ;
633
633
634
+ let negsRe ;
635
+
636
+ if ( negs . length > 0 ) {
637
+ negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
638
+
639
+ if ( needle . trim ( ) == '' ) {
640
+ let idxs = [ ] ;
641
+
642
+ for ( let i = 0 ; i < haystack . length ; i ++ ) {
643
+ if ( ! negsRe . test ( haystack [ i ] ) )
644
+ idxs . push ( i ) ;
645
+ }
646
+
647
+ return [ idxs , null , null ] ;
648
+ }
649
+ }
650
+
634
651
// console.log(negs);
652
+ // console.log(needle);
635
653
636
654
if ( outOfOrder ) {
637
655
// since uFuzzy is an AND-based search, we can iteratively pre-reduce the haystack by searching
@@ -689,10 +707,8 @@ function uFuzzy(opts) {
689
707
let retInfo = null ;
690
708
let retOrder = null ;
691
709
692
- if ( negs . length > 0 ) {
693
- let negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
710
+ if ( negs . length > 0 )
694
711
matches = matches . map ( idxs => idxs . filter ( idx => ! negsRe . test ( haystack [ idx ] ) ) ) ;
695
- }
696
712
697
713
let matchCount = matches . reduce ( ( acc , idxs ) => acc + idxs . length , 0 ) ;
698
714
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ var uFuzzy = (function () {
14
14
15
15
const inf = Infinity ;
16
16
17
- const NEGS_RE = / (?: \s | ^ ) - [ a - z \d ] + / ig;
17
+ const NEGS_RE = / (?: \s + | ^ ) - [ a - z \d ] + / ig;
18
18
19
19
const OPTS = {
20
20
// term segmentation & punct/whitespace merging
@@ -631,10 +631,28 @@ var uFuzzy = (function () {
631
631
632
632
needle = needle . replace ( NEGS_RE , m => {
633
633
negs . push ( m . trim ( ) . slice ( 1 ) ) ;
634
- return ' ' ;
634
+ return '' ;
635
635
} ) ;
636
636
637
+ let negsRe ;
638
+
639
+ if ( negs . length > 0 ) {
640
+ negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
641
+
642
+ if ( needle . trim ( ) == '' ) {
643
+ let idxs = [ ] ;
644
+
645
+ for ( let i = 0 ; i < haystack . length ; i ++ ) {
646
+ if ( ! negsRe . test ( haystack [ i ] ) )
647
+ idxs . push ( i ) ;
648
+ }
649
+
650
+ return [ idxs , null , null ] ;
651
+ }
652
+ }
653
+
637
654
// console.log(negs);
655
+ // console.log(needle);
638
656
639
657
if ( outOfOrder ) {
640
658
// since uFuzzy is an AND-based search, we can iteratively pre-reduce the haystack by searching
@@ -692,10 +710,8 @@ var uFuzzy = (function () {
692
710
let retInfo = null ;
693
711
let retOrder = null ;
694
712
695
- if ( negs . length > 0 ) {
696
- let negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
713
+ if ( negs . length > 0 )
697
714
matches = matches . map ( idxs => idxs . filter ( idx => ! negsRe . test ( haystack [ idx ] ) ) ) ;
698
- }
699
715
700
716
let matchCount = matches . reduce ( ( acc , idxs ) => acc + idxs . length , 0 ) ;
701
717
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const cmp = new Intl.Collator('en').compare;
4
4
5
5
const inf = Infinity ;
6
6
7
- const NEGS_RE = / (?: \s | ^ ) - [ a - z \d ] + / ig;
7
+ const NEGS_RE = / (?: \s + | ^ ) - [ a - z \d ] + / ig;
8
8
9
9
const OPTS = {
10
10
// term segmentation & punct/whitespace merging
@@ -627,10 +627,28 @@ export default function uFuzzy(opts) {
627
627
628
628
needle = needle . replace ( NEGS_RE , m => {
629
629
negs . push ( m . trim ( ) . slice ( 1 ) ) ;
630
- return ' ' ;
630
+ return '' ;
631
631
} ) ;
632
632
633
+ let negsRe ;
634
+
635
+ if ( negs . length > 0 ) {
636
+ negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
637
+
638
+ if ( needle . trim ( ) == '' ) {
639
+ let idxs = [ ] ;
640
+
641
+ for ( let i = 0 ; i < haystack . length ; i ++ ) {
642
+ if ( ! negsRe . test ( haystack [ i ] ) )
643
+ idxs . push ( i ) ;
644
+ }
645
+
646
+ return [ idxs , null , null ] ;
647
+ }
648
+ }
649
+
633
650
// console.log(negs);
651
+ // console.log(needle);
634
652
635
653
if ( outOfOrder ) {
636
654
// since uFuzzy is an AND-based search, we can iteratively pre-reduce the haystack by searching
@@ -688,10 +706,8 @@ export default function uFuzzy(opts) {
688
706
let retInfo = null ;
689
707
let retOrder = null ;
690
708
691
- if ( negs . length > 0 ) {
692
- let negsRe = new RegExp ( negs . join ( '|' ) , 'i' ) ;
709
+ if ( negs . length > 0 )
693
710
matches = matches . map ( idxs => idxs . filter ( idx => ! negsRe . test ( haystack [ idx ] ) ) ) ;
694
- }
695
711
696
712
let matchCount = matches . reduce ( ( acc , idxs ) => acc + idxs . length , 0 ) ;
697
713
You can’t perform that action at this time.
0 commit comments