utils

package
v0.0.11-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNEvenlySpacedElements

func GetNEvenlySpacedElements[T any](array []T, n int) []T

GetNEvenlySpacedElements returns n evenly spaced elements from the given array. The function takes an array of any type and an integer n as input. If the array is empty, it returns an empty array. The function calculates the step size based on the length of the array and n. It then selects the elements at the calculated indices and returns them in a new array.

func ReadFile

func ReadFile(filePath string) ([]byte, error)

ReadFile reads the content of a file specified by the filePath parameter. It returns the content of the file as a byte slice and an error if any occurred.

func SplitOnLastOccurence

func SplitOnLastOccurence(target string, delimiter rune) []string

SplitOnLastOccurence splits the target string on the last occurrence of the specified delimiter. It returns a slice of strings where the first element is the substring before the delimiter, and the second element is the substring after the delimiter. If the delimiter is not found, it returns a slice containing the target string itself.

Types

type MapItem

type MapItem struct {
	Key, Value interface{}
}

type MapSlice

type MapSlice []MapItem

func (MapSlice) MarshalJSON

func (ms MapSlice) MarshalJSON() ([]byte, error)

MarshalJSON converts the MapSlice to its JSON representation. It marshals each key-value pair in the MapSlice to JSON and returns the resulting byte slice. The keys are converted to strings using the default formatting. The returned byte slice represents a JSON object. If an error occurs during marshaling, it returns nil and the error.

type PackageFile

type PackageFile struct {
	Name                 string            `json:"name,omitempty"`
	Version              string            `json:"version,omitempty"`
	Description          string            `json:"description,omitempty"`
	Dependencies         map[string]string `json:"dependencies,omitempty"`
	DevDependencies      map[string]string `json:"devDependencies,omitempty"`
	OptionalDependencies map[string]string `json:"optionalDependencies,omitempty"`
	PeerDependencies     map[string]string `json:"peerDependencies,omitempty"`
	BundleDependencies   []string          `json:"bundleDependencies,omitempty"`
	BundledDependencies  []string          `json:"bundledDependencies,omitempty"`
	WorkSpaces           []string          `json:"workspaces"`
}

func ParsePackageFile

func ParsePackageFile(filePath string) (PackageFile, string, error)

ParsePackageFile parses the package file located at the given file path and returns the parsed package file data, the raw package file data as a string, and any error encountered during the parsing process. The package file is expected to be in JSON format.

Jump to

Keyboard shortcuts

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