20 lines
495 B
Plaintext
20 lines
495 B
Plaintext
"use strict";
|
|
function returnValue(value) {
|
|
return value;
|
|
}
|
|
function formatMessage(message, callback = returnValue) {
|
|
return message.reduce((prev, curr, index) => {
|
|
let msg;
|
|
if (curr instanceof Error) {
|
|
msg = curr.stack || curr.message;
|
|
} else if (typeof curr === "object") {
|
|
msg = JSON.stringify(curr);
|
|
} else {
|
|
msg = String(curr);
|
|
}
|
|
msg = callback(msg);
|
|
return index === 0 ? msg : `${prev} ${msg}`;
|
|
}, "");
|
|
}
|
|
module.exports = formatMessage;
|