t-comm
Version:
专业、稳定、纯粹的工具库
42 lines (40 loc) • 1.14 kB
JavaScript
var DEFAULT_SEPARATOR = ',';
var DEFAULT_LABEL_SEPARATOR = ':';
function parseRobotMessage(info, labelSeparator) {
if (labelSeparator === void 0) {
labelSeparator = DEFAULT_LABEL_SEPARATOR;
}
if (typeof info === 'string') return info;
var _a = info || {},
content = _a.content,
link = _a.link,
label = _a.label,
isTitle = _a.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, separator, labelSeparator) {
if (separator === void 0) {
separator = DEFAULT_SEPARATOR;
}
if (labelSeparator === void 0) {
labelSeparator = 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');
}
export { genRobotMessage, parseRobotMessage };