MCPcopy Index your code
hub / github.com/github/gh-aw / FormatJavaScriptForYAML

Function FormatJavaScriptForYAML

pkg/workflow/js.go:396–416  ·  view source on GitHub ↗

FormatJavaScriptForYAML formats a JavaScript script with proper indentation for embedding in YAML

(script string)

Source from the content-addressed store, hash-verified

394
395// FormatJavaScriptForYAML formats a JavaScript script with proper indentation for embedding in YAML
396func FormatJavaScriptForYAML(script string) []string {
397 if jsLog.Enabled() {
398 jsLog.Printf("Formatting JavaScript for YAML: %d bytes", len(script))
399 }
400 var formattedLines []string
401
402 // Remove JavaScript comments first
403 cleanScript := removeJavaScriptComments(script)
404
405 scriptLines := strings.SplitSeq(cleanScript, "\n")
406 for line := range scriptLines {
407 // Skip empty lines when inlining to YAML
408 if strings.TrimSpace(line) != "" {
409 formattedLines = append(formattedLines, fmt.Sprintf(" %s\n", line))
410 }
411 }
412 if jsLog.Enabled() {
413 jsLog.Printf("Formatted %d lines for YAML", len(formattedLines))
414 }
415 return formattedLines
416}
417
418// WriteJavaScriptToYAML writes a JavaScript script with proper indentation to a strings.Builder
419func WriteJavaScriptToYAML(yaml *strings.Builder, script string) {

Calls 3

removeJavaScriptCommentsFunction · 0.85
EnabledMethod · 0.45
PrintfMethod · 0.45