21 lines
488 B
Plaintext
21 lines
488 B
Plaintext
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}`;
|
|
}, "");
|
|
}
|
|
export {
|
|
formatMessage as default
|
|
};
|