X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Ftemplate-helper.js;h=c72e0ed348415d2c8adf6f1366b1639330819f65;hb=HEAD;hp=7e51bcfbb9058a25287bf934978d9234b368bf80;hpb=f02188f99140aabbd289b610d5968145c83fd057;p=squeep-html-template-helper diff --git a/lib/template-helper.js b/lib/template-helper.js index 7e51bcf..f2f4efe 100644 --- a/lib/template-helper.js +++ b/lib/template-helper.js @@ -10,7 +10,7 @@ const { lazy } = require('@squeep/lazy-property'); /** * Set up expected fields for how we handle error reporting * and whatnot. - * @param {Object} ctx + * @param {object} ctx context */ const initContext = (ctx) => { ctx.errors = []; @@ -19,8 +19,9 @@ const initContext = (ctx) => { /** * Some fields may have values outside normal dates, handle them here. - * @param {Date} date - * @param {String} otherwise + * @param {Date|number} date potential Date or epoch milliseconds + * @param {string} otherwise returned if date is not a date + * @returns {string} date or otherwise */ const dateOrNot = (date, otherwise) => { if (!date) { @@ -42,10 +43,11 @@ const dateOrNot = (date, otherwise) => { * Why is rendering a Date as a string this complicated? * We handle the infinities because pg-promise might provide those in * lieu of a Date object from timestamp fields. - * @param {Date|Number|String} date - * @param {String=} pInf - * @param {String=} nInf - * @param {String=} otherwise + * @param {Date|number|string} date Date, epoch milliseconds, or date string + * @param {string=} pInf returned if date is +Infinity + * @param {string=} nInf returned if date is -Infinity + * @param {string=} otherwise returned if date is something else + * @returns {string} rendered date */ const dateFormat = (date, pInf = 'Never', nInf = 'Forever', otherwise = '') => { const isDatableType = ['number', 'string'].includes(typeof date); @@ -77,10 +79,11 @@ lazy(dateFormat, '_dtf', () => { /** - * Wrap a Date in a