This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,15 @@ function filterFilter() {
133
133
//jshint -W086
134
134
case 'object' :
135
135
//jshint +W086
136
+ if ( ! matchAgainstAnyProp && ( expression !== null ) && ( '$' in expression ) ) {
137
+ var keysCount = 0 ;
138
+ for ( var key in expression ) { keysCount ++ ; }
139
+ if ( keysCount === 1 ) {
140
+ expression = expression . $ ;
141
+ matchAgainstAnyProp = true ;
142
+ }
143
+ }
144
+
136
145
predicateFn = createPredicateFn ( expression , comparator , matchAgainstAnyProp ) ;
137
146
break ;
138
147
default :
Original file line number Diff line number Diff line change @@ -65,6 +65,26 @@ describe('Filter: filter', function() {
65
65
} ) ;
66
66
67
67
68
+ it ( 'should treat expression `{$: \'xyz\'}` as `\'xyz\'`' , function ( ) {
69
+ var items , expr ;
70
+
71
+ items = [ 'something' , 'something else' , 'another thing' ] ;
72
+ expr = { $ : 'some' } ;
73
+ expect ( filter ( items , expr ) . length ) . toBe ( 2 ) ;
74
+ expect ( filter ( items , expr ) ) . toEqual ( [ items [ 0 ] , items [ 1 ] ] ) ;
75
+
76
+ items = [ { val : 'something' } , { val : 'something else' } , { val : 'another thing' } ] ;
77
+ expr = { $ : 'some' } ;
78
+ expect ( filter ( items , expr ) . length ) . toBe ( 2 ) ;
79
+ expect ( filter ( items , expr ) ) . toEqual ( [ items [ 0 ] , items [ 1 ] ] ) ;
80
+
81
+ items = [ 123 , 456 , 789 ] ;
82
+ expr = { $ : 1 } ;
83
+ expect ( filter ( items , expr ) . length ) . toBe ( 1 ) ;
84
+ expect ( filter ( items , expr ) ) . toEqual ( [ items [ 0 ] ] ) ;
85
+ } ) ;
86
+
87
+
68
88
it ( 'should take object as predicate' , function ( ) {
69
89
var items = [ { first : 'misko' , last : 'hevery' } ,
70
90
{ first : 'adam' , last : 'abrons' } ] ;
You can’t perform that action at this time.
0 commit comments