MCPcopy
hub / github.com/esm-dev/esm.sh / formatMap

Function formatMap

internal/importmap/importmap.go:592–613  ·  view source on GitHub ↗
(buf *strings.Builder, m *Imports, indent int)

Source from the content-addressed store, hash-verified

590}
591
592func formatMap(buf *strings.Builder, m *Imports, indent int) {
593 keys := m.Keys()
594 sort.Strings(keys)
595 indentStr := bytes.Repeat([]byte{' ', ' '}, indent)
596 for i, key := range keys {
597 value, ok := m.Get(key)
598 if !ok || value == "" {
599 // ignore empty values
600 continue
601 }
602 buf.Write(indentStr)
603 buf.WriteByte('"')
604 buf.WriteString(key)
605 buf.WriteString("\": \"")
606 buf.WriteString(value)
607 buf.WriteByte('"')
608 if i < len(keys)-1 {
609 buf.WriteByte(',')
610 }
611 buf.WriteByte('\n')
612 }
613}
614
615func newImports(imports map[string]string) *Imports {
616 if imports == nil {

Callers 1

FormatJSONMethod · 0.85

Calls 3

WriteMethod · 0.80
GetMethod · 0.65
KeysMethod · 0.45

Tested by

no test coverage detected