From f5742a7cf96d536333b1d162c2c8f7164ddc1216 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 26 Sep 2019 10:26:03 +0300 Subject: [PATCH 1/7] Fixed issues where scopedData is null --- logic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.js b/logic.js index 6b827df..16cc4b8 100644 --- a/logic.js +++ b/logic.js @@ -318,7 +318,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html ); }else if(op === "all") { - scopedData = jsonLogic.apply(values[0], data); + scopedData = jsonLogic.apply(values[0], data) || []; scopedLogic = values[1]; // All of an empty set is false. Note, some and none have correct fallback after the for loop if( ! scopedData.length) { From 772d4729b0717989157ca7c745d3bd09eba8ce6d Mon Sep 17 00:00:00 2001 From: Ivan Rozhkov Date: Sun, 3 Nov 2019 15:14:13 +0300 Subject: [PATCH 2/7] return undefined for if --- logic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.js b/logic.js index 16cc4b8..dfc08ef 100644 --- a/logic.js +++ b/logic.js @@ -252,7 +252,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html } } if(values.length === i+1) return jsonLogic.apply(values[i], data); - return null; + return undefined; }else if(op === "and") { // Return first falsy, or last for(i=0; i < values.length; i+=1) { current = jsonLogic.apply(values[i], data); From 4b96de92e795a119e200570a213bef0267e0a5e4 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 19 Dec 2019 10:57:14 +0300 Subject: [PATCH 3/7] Added comment operator --- logic.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/logic.js b/logic.js index dfc08ef..022d490 100644 --- a/logic.js +++ b/logic.js @@ -74,6 +74,9 @@ http://ricostacruz.com/cheatsheets/umdjs.html "log": function(a) { console.log(a); return a; }, + "comment": function(a) { + return a; + }, "in": function(a, b) { if(!b || typeof b.indexOf === "undefined") return false; return (b.indexOf(a) !== -1); From b6723e328f4c2de42c737f2ed0516b66c8d099da Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 14 Jul 2021 17:26:03 +0300 Subject: [PATCH 4/7] Update logic.js Pass ROOT_DATA to map operation --- logic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.js b/logic.js index 022d490..f872844 100644 --- a/logic.js +++ b/logic.js @@ -298,7 +298,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html } return scopedData.map(function(datum){ - return jsonLogic.apply(scopedLogic, datum); + return jsonLogic.apply(scopedLogic, Object.assign({}, datum, { 'ROOT_DATA': data })); }); }else if(op === 'reduce'){ From d26fb788d9cabd38583981876088429e0263f3bc Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 14 Jul 2021 18:50:10 +0300 Subject: [PATCH 5/7] Update logic.js I've created a new jsonlogic operation mapWithScope based on map operation Rolled back map operation --- logic.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/logic.js b/logic.js index f872844..30ed6a6 100644 --- a/logic.js +++ b/logic.js @@ -298,7 +298,19 @@ http://ricostacruz.com/cheatsheets/umdjs.html } return scopedData.map(function(datum){ - return jsonLogic.apply(scopedLogic, Object.assign({}, datum, { 'ROOT_DATA': data })); + return jsonLogic.apply(scopedLogic, datum); + }); + + }else if(op === 'mapWithScope'){ + scopedData = jsonLogic.apply(values[0], data); + scopedLogic = values[1]; + + if ( ! Array.isArray(scopedData)) { + return []; + } + + return scopedData.map(function(datum){ + return jsonLogic.apply(scopedLogic, Object.assign({}, { 'LOOP_VAR': datum }, { 'ROOT_DATA': data })); }); }else if(op === 'reduce'){ From 9062d43ac6b141317e267be6023e93af65002324 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 15 Jul 2021 10:54:09 +0300 Subject: [PATCH 6/7] Update logic.js Also added here CURRENT_LOOP_INDEX to get current loop index started from 0 --- logic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.js b/logic.js index 30ed6a6..77cd569 100644 --- a/logic.js +++ b/logic.js @@ -310,7 +310,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html } return scopedData.map(function(datum){ - return jsonLogic.apply(scopedLogic, Object.assign({}, { 'LOOP_VAR': datum }, { 'ROOT_DATA': data })); + return jsonLogic.apply(scopedLogic, Object.assign({}, { 'LOOP_VAR': datum }, { 'ROOT_DATA': data, 'CURRENT_LOOP_INDEX': index })); }); }else if(op === 'reduce'){ From 9e3633144ae5886841ebfd9f614818e0b2e851b4 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 8 Oct 2021 11:28:46 +0300 Subject: [PATCH 7/7] Fixed mapWithScope operation --- logic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic.js b/logic.js index 77cd569..ddf433d 100644 --- a/logic.js +++ b/logic.js @@ -309,7 +309,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html return []; } - return scopedData.map(function(datum){ + return scopedData.map(function(datum, index){ return jsonLogic.apply(scopedLogic, Object.assign({}, { 'LOOP_VAR': datum }, { 'ROOT_DATA': data, 'CURRENT_LOOP_INDEX': index })); });