shunter
Version:
A Node.js application built to read JSON and translate it into HTML
24 lines (18 loc) • 582 B
JavaScript
;
var dateformat = require('dateformat');
module.exports = initHelper;
function initHelper(dust, renderer, config) {
dust.helpers.dateFormat = function (chunk, context, bodies, params) {
var date = null;
var value = null;
params = params || {};
try {
value = (params.date) ? context.resolve(params.date) : null;
date = (value) ? new Date(value.match(/^[0-9]+$/) ? parseInt(value, 10) : value) : new Date();
chunk.write(dateformat(date, params.format || 'yyyy-mm-dd'));
} catch (err) {
config.log.error(err.message);
}
return chunk;
};
}