themes-earthen/helpers.go
Alex Dunmow 49401f1b41 initial: theme plugin earthen
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/earthen.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:27 +08:00

49 lines
1.2 KiB
Go

package main
// getString extracts a string value from content map.
func getString(content map[string]any, key string) string {
if v, ok := content[key].(string); ok {
return v
}
return ""
}
// getBool extracts a bool value from content map. Defaults to defaultVal.
func getBool(content map[string]any, key string, defaultVal bool) bool {
if v, ok := content[key].(bool); ok {
return v
}
return defaultVal
}
// getSlice extracts a slice of maps from content.
func getSlice(content map[string]any, key string) []map[string]any {
if v, ok := content[key].([]any); ok {
result := make([]map[string]any, 0, len(v))
for _, item := range v {
if m, ok := item.(map[string]any); ok {
result = append(result, m)
}
}
return result
}
return nil
}
// getNumberSlice extracts a slice of numbers from content. Handles JSON float64.
func getNumberSlice(content map[string]any, key string) []float64 {
if v, ok := content[key].([]any); ok {
result := make([]float64, 0, len(v))
for _, item := range v {
switch n := item.(type) {
case float64:
result = append(result, n)
case int:
result = append(result, float64(n))
}
}
return result
}
return nil
}