utils

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapitalizeFirst added in v0.0.28

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 added in v0.0.47

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 interface{}, srcs ...interface{})

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 added in v0.0.47

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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