MCPcopy Create free account
hub / github.com/Xyntopia/taskyon / convertToYamlWComments

Function convertToYamlWComments

src/modules/types.ts:291–320  ·  view source on GitHub ↗
(objrepr: string)

Source from the content-addressed store, hash-verified

289export type yamlTaskSchema = z.infer<typeof yamlTaskSchema>;
290
291export 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}

Callers 2

zodToYamlStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected