'use strict'; const tinytim = require('tinytim').tim; //////////////////////////////////////////////////////////////////////////////// // CONSTANTS //////////////////////////////////////////////////////////////////////////////// const TITLE_ERROR = 'error'; const TITLE_MESSAGE = 'message'; //////////////////////////////////////////////////////////////////////////////// // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////// function buildGenericMessage(nameMessage, textMessage) { const jsonMessageResult = {}; jsonMessageResult[nameMessage] = textMessage; return jsonMessageResult; } //////////////////////////////////////////////////////////////////////////////// // PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////// function buildErrorMessage(text) { return buildGenericMessage(TITLE_ERROR, text) } function buildMessage(text) { return buildGenericMessage(TITLE_MESSAGE, text) } function tinytom(literal, data) { if (typeof literal === 'object' && literal !== null) { return JSON.parse(tinytim(JSON.stringify(literal), data)); } else { return tinytim(literal, data); } } module.exports = { tinytom, buildErrorMessage, buildMessage, //For testing buildGenericMessage }