From 622cc391ba8e7e7fecc8c68f51b99625ca125077 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sun, 26 Apr 2020 16:51:46 -0600 Subject: [PATCH] add support for varargs to {{and}} and {{or}} helpers --- src/helpers/and.js | 8 +++++++- src/helpers/or.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/helpers/and.js b/src/helpers/and.js index 2ad2237..5637b15 100644 --- a/src/helpers/and.js +++ b/src/helpers/and.js @@ -1,3 +1,9 @@ 'use strict' -module.exports = (a, b) => a && b +module.exports = (...args) => { + const numArgs = args.length + if (numArgs === 3) return args[0] && args[1] + if (numArgs < 3) throw new Error('{{and}} helper expects at least 2 arguments') + args.pop() + return args.every((it) => it) +} diff --git a/src/helpers/or.js b/src/helpers/or.js index 354612b..eb53907 100644 --- a/src/helpers/or.js +++ b/src/helpers/or.js @@ -1,3 +1,9 @@ 'use strict' -module.exports = (a, b) => a || b +module.exports = (...args) => { + const numArgs = args.length + if (numArgs === 3) return args[0] || args[1] + if (numArgs < 3) throw new Error('{{or}} helper expects at least 2 arguments') + args.pop() + return args.some((it) => it) +} -- 2.11.0