utils

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapitalizeFirst

func CapitalizeFirst(s string) string

CapitalizeFirst converts the first character of a string to uppercase. The rest of the string remains unchanged. Examples:

  • "hello" -> "Hello"
  • "world" -> "World"
  • "" -> ""
  • "already Capitalized" -> "Already Capitalized"

func ExtractSemverVersion

func ExtractSemverVersion(version string) string

ExtractSemverVersion extracts the first version number found in a string. It supports full semver (major.minor.patch) as well as partial versions (major or major.minor). The version can appear anywhere in the string and can have prefixes or suffixes. Examples:

  • "1.2.3" -> "1.2.3"
  • "v1.2.3" -> "1.2.3"
  • "python-3.10.7" -> "3.10.7"
  • "version1.2.3-beta" -> "1.2.3"
  • "requires node 14.2" -> "14.2"
  • "python 3" -> "3"

Returns an empty string if no version number is found.

func MergeStringSlicePointers

func MergeStringSlicePointers(slices ...*[]string) *[]string

MergeStringSlicePointers combines multiple string slice pointers, deduplicates values, and sorts them

func MergeStructs

func MergeStructs(dst any, srcs ...any)

MergeStructs merges multiple structs of the same type, with later values taking precedence. Only non-zero values from later structs will override earlier values.

func ParsePackageWithVersion

func ParsePackageWithVersion(versions []string) map[string]string

ParsePackageWithVersion parses a slice of package specifications in the format "name@version" and returns a map of package names to their versions. If a package has no version specified (no @ symbol), it defaults to "latest". Examples:

  • ["node@14.2"] -> {"node": "14.2"}
  • ["python"] -> {"python": "latest"}
  • ["ruby@3.0.0", "go"] -> {"ruby": "3.0.0", "go": "latest"}
  • ["node@^14.3", "python@>=3.9"] -> {"node": "^14.3", "python": ">=3.9"}

func RemoveDuplicates

func RemoveDuplicates[T comparable](sliceList []T) []T

func StandardizeJSON added in v0.6.0

func StandardizeJSON(b []byte) ([]byte, error)

convert hujson/extended JSON into standardized json

Types

type Semver added in v0.0.58

type Semver struct {
	Major int
	Minor int
	Patch int
}

func ParseSemver added in v0.0.58

func ParseSemver(version string) (*Semver, error)

ParseSemver parses a semantic version string and returns a Semver struct.

Jump to

Keyboard shortcuts

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