2018-03-27 15:30:23 -04:00
|
|
|
const formatMessage = require('format-message');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if `maybeMessage` looks like a message object, and if so pass it to `formatMessage`.
|
|
|
|
* Otherwise, return `maybeMessage` as-is.
|
|
|
|
* @param {*} maybeMessage - something that might be a message descriptor object.
|
|
|
|
* @param {object} [args] - the arguments to pass to `formatMessage` if it gets called.
|
|
|
|
* @param {string} [locale] - the locale to pass to `formatMessage` if it gets called.
|
|
|
|
* @return {string|*} - the formatted message OR the original `maybeMessage` input.
|
|
|
|
*/
|
|
|
|
const maybeFormatMessage = function (maybeMessage, args, locale) {
|
2018-04-09 18:34:46 -04:00
|
|
|
if (maybeMessage && maybeMessage.id && maybeMessage.default) {
|
2018-03-27 15:30:23 -04:00
|
|
|
return formatMessage(maybeMessage, args, locale);
|
|
|
|
}
|
|
|
|
return maybeMessage;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = maybeFormatMessage;
|