(objrepr: string)
| 289 | export type yamlTaskSchema = z.infer<typeof yamlTaskSchema>; |
| 290 | |
| 291 | export function convertToYamlWComments(objrepr: string) { |
| 292 | // Regular expression to match the entire comment section, including the key and optional '>-' |
| 293 | const regex = /( *)(('# .*:)\s*(>-)?)([\s\S]*?)(?=\n\s*\S+:|$)/g; |
| 294 | |
| 295 | return objrepr.replace( |
| 296 | regex, |
| 297 | ( |
| 298 | match, |
| 299 | indent: string, |
| 300 | keyX, |
| 301 | key, |
| 302 | keyEnd: string, |
| 303 | commentBlock: string |
| 304 | ) => { |
| 305 | const isMultiline = !!keyEnd; |
| 306 | // Modify each line of the comment block |
| 307 | let modifiedCommentBlock = []; |
| 308 | if (isMultiline) { |
| 309 | const commentLines = commentBlock.split('\n').filter((l) => l.trim()); |
| 310 | // Trim the first line and apply the indentation to all other lines |
| 311 | modifiedCommentBlock = commentLines.map((line) => { |
| 312 | return indent + '# ' + line.trim(); |
| 313 | }); |
| 314 | } else { |
| 315 | modifiedCommentBlock = [indent + '# ' + commentBlock]; |
| 316 | } |
| 317 | return modifiedCommentBlock.join('\n'); |
| 318 | } |
| 319 | ); |
| 320 | } |
no outgoing calls
no test coverage detected