From: Dan Allen Date: Sun, 26 Apr 2020 22:51:46 +0000 (-0600) Subject: add support for varargs to {{and}} and {{or}} helpers X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=622cc391ba8e7e7fecc8c68f51b99625ca125077;p=working%2Feg-antora.git add support for varargs to {{and}} and {{or}} helpers --- 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) +}