From a991f45dddf0c1449db9b528d9d51743d1929ce7 Mon Sep 17 00:00:00 2001 From: Bryan Morris Date: Tue, 28 Feb 2017 12:32:44 -0700 Subject: [PATCH 1/3] add 'some', 'all', 'none' operators --- logic.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/logic.js b/logic.js index 245e447..77075f3 100644 --- a/logic.js +++ b/logic.js @@ -249,6 +249,27 @@ http://ricostacruz.com/cheatsheets/umdjs.html } } return current; // Last + }else if(op === "some") { + let localData = jsonLogic.apply(values[0], data) + let localLogic = values[1] + let result = localData.map(function (item) { + return !!jsonLogic.apply(localLogic, item) + }) + return result.includes(true) + }else if(op === "all") { + let localData = jsonLogic.apply(values[0], data) + let localLogic = values[1] + let result = localData.map(function (item) { + return !!jsonLogic.apply(localLogic, item) + }) + return !result.includes(false) + }else if(op === "none") { + let localData = jsonLogic.apply(values[0], data) + let localLogic = values[1] + let result = localData.map(function (item) { + return !!jsonLogic.apply(localLogic, item) + }) + return !result.includes(true) } From 4300b578b5b9ed5d602451d1f2678c67fbd0534e Mon Sep 17 00:00:00 2001 From: Bryan Morris Date: Thu, 16 Mar 2017 16:07:53 -0700 Subject: [PATCH 2/3] check that the logic object....has logic. --- logic.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/logic.js b/logic.js index 77075f3..b322408 100644 --- a/logic.js +++ b/logic.js @@ -201,6 +201,11 @@ http://ricostacruz.com/cheatsheets/umdjs.html data = data || {}; + // If logic is empty object, return true. + if (Object.keys(logic).length === 0) { + return true + } + var op = Object.keys(logic)[0]; var values = logic[op]; var i; @@ -278,7 +283,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html return jsonLogic.apply(val, data); }); - if(typeof operations[op] === "function") { return operations[op].apply(data, values); }else if(op.indexOf(".") > 0) { // Contains a dot, and not in the 0th position From a80edf05a948ad2b684c3a8360859933badecbd8 Mon Sep 17 00:00:00 2001 From: Bryan Morris Date: Thu, 6 Apr 2017 11:36:34 -0700 Subject: [PATCH 3/3] unbreak uglify --- logic.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/logic.js b/logic.js index b322408..078f36c 100644 --- a/logic.js +++ b/logic.js @@ -255,26 +255,26 @@ http://ricostacruz.com/cheatsheets/umdjs.html } return current; // Last }else if(op === "some") { - let localData = jsonLogic.apply(values[0], data) - let localLogic = values[1] - let result = localData.map(function (item) { - return !!jsonLogic.apply(localLogic, item) + var scopedData = jsonLogic.apply(values[0], data) + var scopedLogic = values[1] + var scopedResult = scopedData.map(function (item) { + return !!jsonLogic.apply(scopedLogic, item) }) - return result.includes(true) + return scopedResult.includes(true) }else if(op === "all") { - let localData = jsonLogic.apply(values[0], data) - let localLogic = values[1] - let result = localData.map(function (item) { - return !!jsonLogic.apply(localLogic, item) + var scopedData = jsonLogic.apply(values[0], data) + var scopedLogic = values[1] + var scopedResult = scopedData.map(function (item) { + return !!jsonLogic.apply(scopedLogic, item) }) - return !result.includes(false) + return !scopedResult.includes(false) }else if(op === "none") { - let localData = jsonLogic.apply(values[0], data) - let localLogic = values[1] - let result = localData.map(function (item) { - return !!jsonLogic.apply(localLogic, item) + var scopedData = jsonLogic.apply(values[0], data) + var scopedLogic = values[1] + var scopedResult = scopedData.map(function (item) { + return !!jsonLogic.apply(scopedLogic, item) }) - return !result.includes(true) + return !scopedResult.includes(true) }