diff --git a/logic.js b/logic.js index 245e447..078f36c 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; @@ -249,6 +254,27 @@ http://ricostacruz.com/cheatsheets/umdjs.html } } return current; // Last + }else if(op === "some") { + var scopedData = jsonLogic.apply(values[0], data) + var scopedLogic = values[1] + var scopedResult = scopedData.map(function (item) { + return !!jsonLogic.apply(scopedLogic, item) + }) + return scopedResult.includes(true) + }else if(op === "all") { + var scopedData = jsonLogic.apply(values[0], data) + var scopedLogic = values[1] + var scopedResult = scopedData.map(function (item) { + return !!jsonLogic.apply(scopedLogic, item) + }) + return !scopedResult.includes(false) + }else if(op === "none") { + var scopedData = jsonLogic.apply(values[0], data) + var scopedLogic = values[1] + var scopedResult = scopedData.map(function (item) { + return !!jsonLogic.apply(scopedLogic, item) + }) + return !scopedResult.includes(true) } @@ -257,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