@@ -220,7 +220,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html
220
220
var current ;
221
221
var scopedLogic ;
222
222
var scopedData ;
223
- var filtered ;
224
223
var initial ;
225
224
226
225
// easy syntax for unary operators, like {"var" : "x"} instead of strict {"var" : ["x"]}
@@ -314,7 +313,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
314
313
scopedData = jsonLogic . apply ( values [ 0 ] , data ) ;
315
314
scopedLogic = values [ 1 ] ;
316
315
// All of an empty set is false. Note, some and none have correct fallback after the for loop
317
- if ( ! scopedData . length ) {
316
+ if ( ! Array . isArray ( scopedData ) || ! scopedData . length ) {
318
317
return false ;
319
318
}
320
319
for ( i = 0 ; i < scopedData . length ; i += 1 ) {
@@ -324,11 +323,31 @@ http://ricostacruz.com/cheatsheets/umdjs.html
324
323
}
325
324
return true ; // All were truthy
326
325
} else if ( op === "none" ) {
327
- filtered = jsonLogic . apply ( { filter : values } , data ) ;
328
- return filtered . length === 0 ;
326
+ scopedData = jsonLogic . apply ( values [ 0 ] , data ) ;
327
+ scopedLogic = values [ 1 ] ;
328
+
329
+ if ( ! Array . isArray ( scopedData ) || ! scopedData . length ) {
330
+ return true ;
331
+ }
332
+ for ( i = 0 ; i < scopedData . length ; i += 1 ) {
333
+ if ( jsonLogic . truthy ( jsonLogic . apply ( scopedLogic , scopedData [ i ] ) ) ) {
334
+ return false ; // First truthy, short circuit
335
+ }
336
+ }
337
+ return true ; // None were truthy
329
338
} else if ( op === "some" ) {
330
- filtered = jsonLogic . apply ( { filter : values } , data ) ;
331
- return filtered . length > 0 ;
339
+ scopedData = jsonLogic . apply ( values [ 0 ] , data ) ;
340
+ scopedLogic = values [ 1 ] ;
341
+
342
+ if ( ! Array . isArray ( scopedData ) || ! scopedData . length ) {
343
+ return false ;
344
+ }
345
+ for ( i = 0 ; i < scopedData . length ; i += 1 ) {
346
+ if ( jsonLogic . truthy ( jsonLogic . apply ( scopedLogic , scopedData [ i ] ) ) ) {
347
+ return true ; // First truthy, short circuit
348
+ }
349
+ }
350
+ return false ; // None were truthy
332
351
}
333
352
334
353
// Everyone else gets immediate depth-first recursion
@@ -346,7 +365,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html
346
365
var sub_ops = String ( op ) . split ( "." ) ;
347
366
var operation = operations ;
348
367
for ( i = 0 ; i < sub_ops . length ; i ++ ) {
349
-
350
368
if ( ! operation . hasOwnProperty ( sub_ops [ i ] ) ) {
351
369
throw new Error ( "Unrecognized operation " + op +
352
370
" (failed at " + sub_ops . slice ( 0 , i + 1 ) . join ( "." ) + ")" ) ;
@@ -377,7 +395,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
377
395
collection . push ( values [ 0 ] ) ;
378
396
} else {
379
397
// Recursion!
380
- values . map ( function ( val ) {
398
+ values . forEach ( function ( val ) {
381
399
collection . push . apply ( collection , jsonLogic . uses_data ( val ) ) ;
382
400
} ) ;
383
401
}
0 commit comments