utils

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package utils provides general-purpose utilities for JSON handling and panic recovery.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRecoveredPanic is returned when a panic is recovered and converted to an error.
	ErrRecoveredPanic = errors.New("recovered panic")

	// ErrCouldNotRepairJSON is returned when malformed JSON cannot be automatically fixed.
	ErrCouldNotRepairJSON = errors.New("malformed JSON could not be repaired")
)
View Source
var ErrInvalidStringSetValue = errors.New("invalid string-set value")

ErrInvalidStringSetValue indicates invalid StringSet definition.

Functions

func JSONFromMarkdown

func JSONFromMarkdown(content string) string

JSONFromMarkdown extracts JSON content from a given Markdown string. If a JSON block is found, it returns the JSON content as a string. If no JSON block is found, it returns the original content.

func NoPanic

func NoPanic(fn func() error) (err error)

NoPanic executes the provided function and recovers from any panic by converting it to error if that occurs.

func RepairTextJSON

func RepairTextJSON(content string) (string, error)

RepairTextJSON attempts to repair common issues with plain-text JSON generated by LLMs. If the input is already valid JSON, it is returned as-is.

func SplitLines added in v0.6.1

func SplitLines(text string) []string

SplitLines splits text by newlines supporting both \n and \r\n and preserves empty lines. Returns an empty slice for empty input.

Types

type StringSet added in v0.2.0

type StringSet struct {
	// contains filtered or unexported fields
}

StringSet represents a set of unique string values.

func NewStringSet added in v0.2.0

func NewStringSet(items ...string) StringSet

NewStringSet creates a new StringSet from the given items, discarding duplicates.

func (StringSet) Any added in v0.2.0

func (s StringSet) Any(condition func(string) bool) bool

Any returns true if any value in the set satisfies the given condition.

func (StringSet) Map added in v0.2.0

func (s StringSet) Map(f func(string) string) StringSet

Map returns a new StringSet with f applied to each value, discarding duplicates.

func (StringSet) MarshalYAML added in v0.2.0

func (s StringSet) MarshalYAML() (interface{}, error)

MarshalYAML implements YAML marshaling for StringSet.

func (*StringSet) UnmarshalYAML added in v0.2.0

func (s *StringSet) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML allows StringSet to be loaded from either a string or a list of strings.

func (StringSet) Values added in v0.2.0

func (s StringSet) Values() []string

Values returns a copy of the set's values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL