Code:function transform(input) {
var t = input.tweet || {};
var a = input.author || {};
var authorOk = a && a.status === 'success';
function fmtNum(n) {
if (!n || n < 1) return '';
if (n >= 1000000) return (n / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
if (n >= 1000) return (n / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
return String(n);
}
function relativeTime(iso) {
var ms = Date.parse(iso);
if (isNaN(ms)) return '';
var deltaSec = Math.floor((Date.now() - ms) / 1000);
if (deltaSec < 5) return 'just now';
if (deltaSec < 60) return deltaSec + 's ago';
if (deltaSec < 3600) return Math.floor(deltaSec / 60) + 'm ago';
if (deltaSec < 86400) return Math.floor(deltaSec / 3600) + 'h ago';
if (deltaSec < 7 * 86400) return Math.floor(deltaSec / 86400) + 'd ago';
var d = new Date(ms);
var mo = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
return mo[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear();
}
function escapeMd(s) {
if (!s) return '';
return String(s).replace(/([\\*_\[\]`])/g, '\\$1');
}
function truncateAtWord(s, maxLen) {
if (!s) return '';
s = String(s).replace(/\n/g, ' ').trim();
if (s.length <= maxLen) return s;
var cut = s.slice(0, maxLen);
var lastSpace = cut.lastIndexOf(' ');
if (lastSpace > 0) return cut.slice(0, lastSpace) + '…';
return cut + '…';
}
function sanitizeBio(s) {
if (!s) return '';
s = String(s).replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
s = s.replace(/https?:\/\/\S+/g, '').replace(/\s+/g, ' ').trim();
for (var iter = 0; iter < 5; iter++) {
var before = s;
s = s.replace(/[\s,.:;\-—–|·\/]+$/g, '').trim();
s = s.replace(/\s+(at|on|in|to|via|and|or|&|plus|more|of|the|my)$/i, '').trim();
if (s === before) break;
}
if (s.length < 3) return '';
return s;
}
var label;
if (t.hasQuotedTweet) label = 'Quote';
else if (t.isReply) label = 'Reply';
else label = 'New tweet';
var followers = (authorOk && a.followers) ? a.followers : (t.authorFollowers || 0);
var isVerified = authorOk ? !!a.isBlueVerified : !!t.authorIsBlueVerified;
var verifiedMark = isVerified ? ' ✓' : '';
var username = t.authorUsername || 'unknown';
var bioSnippet = (authorOk && a.description) ? truncateAtWord(sanitizeBio(a.description), 80) : '';
var location = (authorOk && a.location) ? String(a.location).trim() : '';
var timeStr = relativeTime(t.createdAt);
var rawText = String(t.text || '');
if (t.isReply && t.inReplyToUsername) {
var mentionRe = new RegExp('^@' + t.inReplyToUsername + '\\s+', 'i');
rawText = rawText.replace(mentionRe, '');
}
var strippedText = rawText.replace(/(\s*https?:\/\/t\.co\/\w+\s*)+$/g, '').trim();
// If strip emptied the text and we don't have hasMedia=true to render a
// media link, keep the original text so the body isn't blank. The t.co
// URL is ugly but at least gives a click-through.
if (!strippedText && !t.hasMedia) {
strippedText = rawText.trim();
}
var safeText = escapeMd(strippedText);
var lines = [];
lines.push('**' + label + '** — **@' + username + '**' + verifiedMark + ' · ' + (fmtNum(followers) || '0') + ' followers');
var line2 = [];
if (bioSnippet) line2.push(bioSnippet);
if (location) line2.push(location);
if (timeStr) line2.push(timeStr);
if (line2.length > 0) lines.push(line2.join(' · '));
var mediaLine = '';
if (t.hasMedia) {
var typeLabel;
if (t.mediaType === 'photo') typeLabel = '📸 Photo';
else if (t.mediaType === 'video') typeLabel = '🎥 Video';
else if (t.mediaType === 'animated_gif') typeLabel = '🎞 GIF';
else typeLabel = '📎 Media';
mediaLine = t.mediaUrl ? '[' + typeLabel + ' →](' + t.mediaUrl + ')' : typeLabel + ' attached';
}
var body = [];
if (t.isReply && t.inReplyToUsername) {
body.push('↪ Replying to **@' + t.inReplyToUsername + '**:');
}
if (safeText) body.push(safeText);
if (mediaLine) {
if (body.length > 0) body.push('');
body.push(mediaLine);
}
if (body.length > 0) {
lines.push('');
for (var i = 0; i < body.length; i++) lines.push(body[i]);
}
if (t.hasQuotedTweet && t.quotedTweetText) {
var qText = truncateAtWord(escapeMd(t.quotedTweetText), 200);
lines.push('');
lines.push('↳ Quoting:');
lines.push('> ' + qText);
}
var metrics = [];
if (t.replyCount > 0) metrics.push(fmtNum(t.replyCount) + ' 💬');
if (t.retweetCount > 0) metrics.push(fmtNum(t.retweetCount) + ' 🔁');
if (t.likeCount > 0) metrics.push(fmtNum(t.likeCount) + ' ♥');
if (t.viewCount > 0) metrics.push(fmtNum(t.viewCount) + ' 👁');
if (metrics.length > 0) {
lines.push('');
lines.push(metrics.join(' · '));
}
if (t.tweetUrl) {
lines.push('');
lines.push('[View on X →](' + t.tweetUrl + ')');
}
return lines.join('\n');
}
Input:{"author":"{{get_author_info.result}}","tweet":"{{root.result}}"}