2019-04-24 21:01:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-11-11 16:43:08 +00:00
|
|
|
const tinytim = require('tinytim').tim;
|
|
|
|
|
|
2019-04-24 21:01:54 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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)
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 16:43:08 +00:00
|
|
|
function tinytom(literal, data) {
|
|
|
|
|
if (typeof literal === 'object' && literal !== null) {
|
|
|
|
|
return JSON.parse(tinytim(JSON.stringify(literal), data));
|
|
|
|
|
} else {
|
|
|
|
|
return tinytim(literal, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 21:01:54 +00:00
|
|
|
module.exports = {
|
2019-11-11 16:43:08 +00:00
|
|
|
tinytom,
|
2019-04-24 21:01:54 +00:00
|
|
|
buildErrorMessage,
|
|
|
|
|
buildMessage,
|
|
|
|
|
//For testing
|
|
|
|
|
buildGenericMessage
|
|
|
|
|
}
|