(text: string)
| 221 | * Only wraps URLs not already inside Slack link syntax (< >). |
| 222 | */ |
| 223 | export function wrapUrlsForSlack(text: string): string { |
| 224 | // Match bare URLs (http/https) not already wrapped in < > |
| 225 | // Use negative lookbehind for < and ensure URL isn't followed by > |
| 226 | // Also skip URLs inside backtick code spans |
| 227 | return text.replace( |
| 228 | /(?<![<`])(https?:\/\/[^\s>)`]+)/g, |
| 229 | (match, url, offset) => { |
| 230 | // Check if we're inside a backtick code span |
| 231 | const before = text.substring(0, offset); |
| 232 | const backtickCount = (before.match(/`/g) || []).length; |
| 233 | if (backtickCount % 2 === 1) { |
| 234 | return match; // Inside code span, don't wrap |
| 235 | } |
| 236 | return `<${url}>`; |
| 237 | } |
| 238 | ); |
| 239 | } |
| 240 | |
| 241 | export interface BareJsonGuardResult { |
| 242 | text: string; |
no outgoing calls
no test coverage detected