t-comm
Version:
专业、稳定、纯粹的工具库
41 lines (37 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var DEFAULT_SEPARATOR = ',';
var DEFAULT_LABEL_SEPARATOR = ':';
function parseRobotMessage(info) {
var labelSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LABEL_SEPARATOR;
if (typeof info === 'string') return info;
var _ref = info || {},
content = _ref.content,
link = _ref.link,
label = _ref.label,
isTitle = _ref.isTitle;
if (link) {
return "[".concat(content, "](").concat(link, ")");
}
if (label) {
return "".concat(label).concat(labelSeparator).concat(content);
}
if (isTitle) {
return "\u3010".concat(content, "\u3011");
}
return content;
}
function genRobotMessage(list) {
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_SEPARATOR;
var labelSeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_LABEL_SEPARATOR;
return list.map(function (message) {
if (typeof message === 'string') {
return message;
}
return message.map(function (messageItem) {
return parseRobotMessage(messageItem, labelSeparator);
}).join(separator);
}).join('\n');
}
exports.genRobotMessage = genRobotMessage;
exports.parseRobotMessage = parseRobotMessage;