twfn

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileANSIFilter

func CompileANSIFilter() *regexp.Regexp

CompileANSIFilter constructs and compiles a regex for matching ANSI sequences. It supports both control sequences and operating system commands like hyperlinks.

func ConvertToSorted

func ConvertToSorted(m map[int]int) []int

ConvertToSorted returns a sorted slice of map values by key order. It is useful for converting maps into ordered table structures.

func ConvertToSortedKeys

func ConvertToSortedKeys[V any](m map[int]V) []int

ConvertToSortedKeys returns sorted integer keys of a generic map. This helps when iterating over maps in a consistent order.

func DisplayWidth

func DisplayWidth(str string) int

DisplayWidth calculates the visual width of a string. ANSI escape sequences are stripped before measurement for accuracy.

func IsNumOrSpace

func IsNumOrSpace(r rune) bool

IsNumOrSpace checks if a rune is a digit or space character. It is used for safely replacing characters in formatting logic.

func IsNumeric

func IsNumeric(s string) bool

IsNumeric returns true if a string represents a valid number. It supports both integers and floating-point values.

func MapKeys

func MapKeys[K comparable, V any](m map[K]V) []K

MapKeys GetMapKeys returns a slice containing all keys from the input map

func Max

func Max(a, b int) int

Max returns the greater of two integer values. Simple helper for comparison logic.

func Min

func Min(a, b int) int

func Or

func Or(cond bool, valid, inValid string) string

Or returns 'valid' if cond is true; otherwise returns 'inValid'. It simplifies ternary-like decisions for string output.

func PadCenter

func PadCenter(s, pad string, width int) string

PadCenter centers the input string within a fixed width using the pad character. If the string is smaller, extra padding is split between left and right.

func PadLeft

func PadLeft(s, pad string, width int) string

PadLeft right-aligns the string within the specified width. The remaining space on the left is filled using the pad string.

func PadRight

func PadRight(s, pad string, width int) string

PadRight left-aligns the string within the specified width. The remaining space on the right is filled using the pad string.

func SplitCamelCase

func SplitCamelCase(src string) (entries []string)

SplitCamelCase breaks a camelCase or PascalCase string into word segments. It handles transitions between uppercase and lowercase characters.

func Title

func Title(name string) string

Title normalizes and uppercases a label string for use in headers. It replaces underscores and select dots with spaces, trimming whitespace.

func TruncateString

func TruncateString(s string, maxWidth int, suffix ...string) string

TruncateString shortens a string to a max width while preserving ANSI color codes. An optional suffix (like "...") can be appended to indicate truncation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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