@@ -114,11 +114,11 @@ http://ricostacruz.com/cheatsheets/umdjs.html
114
114
"/" : function ( a , b ) {
115
115
return a / b ;
116
116
} ,
117
- min : function ( ) {
118
- return Math . min . apply ( this , arguments ) ;
117
+ min : function ( ... args ) {
118
+ return Math . min ( ... args ) ;
119
119
} ,
120
- max : function ( ) {
121
- return Math . max . apply ( this , arguments ) ;
120
+ max : function ( ... args ) {
121
+ return Math . max ( ... args ) ;
122
122
} ,
123
123
merge : function ( ) {
124
124
return Array . prototype . reduce . call (
@@ -129,9 +129,8 @@ http://ricostacruz.com/cheatsheets/umdjs.html
129
129
[ ]
130
130
) ;
131
131
} ,
132
- var : function ( a , b ) {
132
+ var : function ( data , a , b ) {
133
133
var not_found = b === undefined ? null : b ;
134
- var data = this ;
135
134
if ( typeof a === "undefined" || a === "" || a === null ) {
136
135
return data ;
137
136
}
@@ -148,7 +147,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
148
147
}
149
148
return data ;
150
149
} ,
151
- missing : function ( ) {
150
+ missing : function ( data , ... args ) {
152
151
/*
153
152
Missing can receive many keys as many arguments, like {"missing:[1,2]}
154
153
Missing can also receive *one* argument that is an array of keys,
@@ -157,21 +156,21 @@ http://ricostacruz.com/cheatsheets/umdjs.html
157
156
*/
158
157
159
158
var missing = [ ] ;
160
- var keys = Array . isArray ( arguments [ 0 ] ) ? arguments [ 0 ] : arguments ;
159
+ var keys = Array . isArray ( args [ 0 ] ) ? args [ 0 ] : args ;
161
160
162
161
for ( var i = 0 ; i < keys . length ; i ++ ) {
163
162
var key = keys [ i ] ;
164
- var value = jsonLogic . apply ( { var : key } , this ) ;
163
+ var value = jsonLogic . apply ( { var : key } , data ) ;
165
164
if ( value === null || value === "" ) {
166
165
missing . push ( key ) ;
167
166
}
168
167
}
169
168
170
169
return missing ;
171
170
} ,
172
- missing_some : function ( need_count , options ) {
171
+ missing_some : function ( data , need_count , options ) {
173
172
// missing_some takes two arguments, how many (minimum) items must be present, and an array of keys (just like 'missing') to check for presence.
174
- var are_missing = jsonLogic . apply ( { missing : options } , this ) ;
173
+ var are_missing = jsonLogic . apply ( { missing : options } , data ) ;
175
174
176
175
if ( options . length - are_missing . length >= need_count ) {
177
176
return [ ] ;
@@ -355,6 +354,15 @@ http://ricostacruz.com/cheatsheets/umdjs.html
355
354
}
356
355
}
357
356
return false ; // None were truthy
357
+ } else if ( op === "var" ) {
358
+ return operations . var (
359
+ data ,
360
+ ...values . map ( ( val ) => jsonLogic . apply ( val , data ) )
361
+ ) ;
362
+ } else if ( op === "missing" ) {
363
+ return operations . missing ( data , ...values . map ( ( val ) => jsonLogic . apply ( val , data ) ) ) ;
364
+ } else if ( op === "missing_some" ) {
365
+ return operations . missing_some ( data , ...values . map ( ( val ) => jsonLogic . apply ( val , data ) ) ) ;
358
366
}
359
367
360
368
// Everyone else gets immediate depth-first recursion
@@ -366,7 +374,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
366
374
// Structured commands like % or > can name formal arguments while flexible commands (like missing or merge) can operate on the pseudo-array arguments
367
375
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
368
376
if ( operations . hasOwnProperty ( op ) && typeof operations [ op ] === "function" ) {
369
- return operations [ op ] . apply ( data , values ) ;
377
+ return operations [ op ] ( ... values ) ;
370
378
} else if ( op . indexOf ( "." ) > 0 ) {
371
379
// Contains a dot, and not in the 0th position
372
380
var sub_ops = String ( op ) . split ( "." ) ;
0 commit comments