60
60
* Primitive values are converted to strings. Objects are not compared against primitives,
61
61
* unless they have a custom `toString` method (e.g. `Date` objects).
62
62
*
63
- * @param {string= } specialKey The special property name that matches against any property.
63
+ * @param {string= } anyPropertyKey The special property name that matches against any property.
64
64
* By default `$`.
65
65
*
66
66
* @example
133
133
*/
134
134
135
135
function filterFilter ( ) {
136
- return function ( array , expression , comparator , specialKey ) {
136
+ return function ( array , expression , comparator , anyPropertyKey ) {
137
137
if ( ! isArrayLike ( array ) ) {
138
138
if ( array == null ) {
139
139
return array ;
@@ -142,7 +142,7 @@ function filterFilter() {
142
142
}
143
143
}
144
144
145
- specialKey = specialKey || '$' ;
145
+ anyPropertyKey = anyPropertyKey || '$' ;
146
146
var expressionType = getTypeForFilter ( expression ) ;
147
147
var predicateFn ;
148
148
var matchAgainstAnyProp ;
@@ -159,7 +159,7 @@ function filterFilter() {
159
159
//jshint -W086
160
160
case 'object' :
161
161
//jshint +W086
162
- predicateFn = createPredicateFn ( expression , comparator , specialKey , matchAgainstAnyProp ) ;
162
+ predicateFn = createPredicateFn ( expression , comparator , anyPropertyKey , matchAgainstAnyProp ) ;
163
163
break ;
164
164
default :
165
165
return array ;
@@ -170,8 +170,8 @@ function filterFilter() {
170
170
}
171
171
172
172
// Helper functions for `filterFilter`
173
- function createPredicateFn ( expression , comparator , specialKey , matchAgainstAnyProp ) {
174
- var shouldMatchPrimitives = isObject ( expression ) && ( specialKey in expression ) ;
173
+ function createPredicateFn ( expression , comparator , anyPropertyKey , matchAgainstAnyProp ) {
174
+ var shouldMatchPrimitives = isObject ( expression ) && ( anyPropertyKey in expression ) ;
175
175
var predicateFn ;
176
176
177
177
if ( comparator === true ) {
@@ -199,25 +199,25 @@ function createPredicateFn(expression, comparator, specialKey, matchAgainstAnyPr
199
199
200
200
predicateFn = function ( item ) {
201
201
if ( shouldMatchPrimitives && ! isObject ( item ) ) {
202
- return deepCompare ( item , expression [ specialKey ] , comparator , specialKey , false ) ;
202
+ return deepCompare ( item , expression [ anyPropertyKey ] , comparator , anyPropertyKey , false ) ;
203
203
}
204
- return deepCompare ( item , expression , comparator , specialKey , matchAgainstAnyProp ) ;
204
+ return deepCompare ( item , expression , comparator , anyPropertyKey , matchAgainstAnyProp ) ;
205
205
} ;
206
206
207
207
return predicateFn ;
208
208
}
209
209
210
- function deepCompare ( actual , expected , comparator , specialKey , matchAgainstAnyProp , dontMatchWholeObject ) {
210
+ function deepCompare ( actual , expected , comparator , anyPropertyKey , matchAgainstAnyProp , dontMatchWholeObject ) {
211
211
var actualType = getTypeForFilter ( actual ) ;
212
212
var expectedType = getTypeForFilter ( expected ) ;
213
213
214
214
if ( ( expectedType === 'string' ) && ( expected . charAt ( 0 ) === '!' ) ) {
215
- return ! deepCompare ( actual , expected . substring ( 1 ) , comparator , specialKey , matchAgainstAnyProp ) ;
215
+ return ! deepCompare ( actual , expected . substring ( 1 ) , comparator , anyPropertyKey , matchAgainstAnyProp ) ;
216
216
} else if ( isArray ( actual ) ) {
217
217
// In case `actual` is an array, consider it a match
218
218
// if ANY of it's items matches `expected`
219
219
return actual . some ( function ( item ) {
220
- return deepCompare ( item , expected , comparator , specialKey , matchAgainstAnyProp ) ;
220
+ return deepCompare ( item , expected , comparator , anyPropertyKey , matchAgainstAnyProp ) ;
221
221
} ) ;
222
222
}
223
223
@@ -226,21 +226,21 @@ function deepCompare(actual, expected, comparator, specialKey, matchAgainstAnyPr
226
226
var key ;
227
227
if ( matchAgainstAnyProp ) {
228
228
for ( key in actual ) {
229
- if ( ( key . charAt ( 0 ) !== '$' ) && deepCompare ( actual [ key ] , expected , comparator , specialKey , true ) ) {
229
+ if ( ( key . charAt ( 0 ) !== '$' ) && deepCompare ( actual [ key ] , expected , comparator , anyPropertyKey , true ) ) {
230
230
return true ;
231
231
}
232
232
}
233
- return dontMatchWholeObject ? false : deepCompare ( actual , expected , comparator , specialKey , false ) ;
233
+ return dontMatchWholeObject ? false : deepCompare ( actual , expected , comparator , anyPropertyKey , false ) ;
234
234
} else if ( expectedType === 'object' ) {
235
235
for ( key in expected ) {
236
236
var expectedVal = expected [ key ] ;
237
237
if ( isFunction ( expectedVal ) || isUndefined ( expectedVal ) ) {
238
238
continue ;
239
239
}
240
240
241
- var matchAnyProperty = key === specialKey ;
241
+ var matchAnyProperty = key === anyPropertyKey ;
242
242
var actualVal = matchAnyProperty ? actual : actual [ key ] ;
243
- if ( ! deepCompare ( actualVal , expectedVal , comparator , specialKey , matchAnyProperty , matchAnyProperty ) ) {
243
+ if ( ! deepCompare ( actualVal , expectedVal , comparator , anyPropertyKey , matchAnyProperty , matchAnyProperty ) ) {
244
244
return false ;
245
245
}
246
246
}
0 commit comments