utils

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package utils contains utility function for errors, node package manager, text, progressbar, github.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertJSStringToStringArray added in v0.11.0

func ConvertJSStringToStringArray(value string) string

ConvertJSStringToStringArray returns a JS/TS array of string from a comma separated JS/TS string as input.

func CurrentYear

func CurrentYear() string

CurrentYear returns the current calendar year as a string.

func ExitIfError added in v0.5.0

func ExitIfError(err error)

ExitIfError panics on os.Exit(1) if error.

func GetInstalledNPMClientList added in v0.3.0

func GetInstalledNPMClientList() []npmc.NPMClient

GetInstalledNPMClientList returns the list of installed npmClient as slice of NPMClient.

func GetNPMClientInfo added in v0.3.0

func GetNPMClientInfo(name string) (bool, string)

GetNPMClientInfo returns true and npm client version as string.

func GetNPMClientNames added in v0.3.0

func GetNPMClientNames(items []npmc.NPMClient) []string

GetNPMClientNames returns the list of installed npmClient as slice of strings.

func GetSelectedNPMClient added in v0.3.0

func GetSelectedNPMClient(in []npmc.NPMClient, name string) npmc.NPMClient

GetSelectedNPMClient returns the selected NPMClient struct out of the available ones.

func IsEmpty added in v0.10.0

func IsEmpty(txt string) bool

IsEmpty returns true if the string is empty.

func IsEmptySlice added in v0.11.0

func IsEmptySlice(txt []string) bool

IsEmptySlice returns true if the string slice is empty.

func IsError added in v0.5.0

func IsError(err error, showMessage bool) bool

IsError returns true if error is not nil. If showMessage is true it prints out a warning with the error message.

func IsValidURL added in v0.8.0

func IsValidURL(input string) bool

IsValidURL returns true if the input string is a well-structured url

func MinusOne added in v0.10.0

func MinusOne(x int) int

MinusOne subtract one to the integer parameter.

func PlusOne

func PlusOne(x int) int

PlusOne adds one to the integer parameter.

func ReplaceIfNested added in v0.9.0

func ReplaceIfNested(txt string) string

ReplaceIfNested returns a copy of string to be used as variable name when a resource name is a nested one.

func RetrieveCSSLib added in v0.11.0

func RetrieveCSSLib(appFS afero.Fs, pathToPkgJSON string) (string, error)

RetrieveCSSLib returns the css lib name used by the project.

func RetrievePackageManagerFromPkgJSON added in v0.7.0

func RetrievePackageManagerFromPkgJSON(appFS afero.Fs, pathToPkgJSON string) (npmc.NPMClient, error)

RetrievePackageManagerFromPkgJSON returns NPMClient struct parsing the package.json file.

func RetrieveProjectName added in v0.5.0

func RetrieveProjectName(appFS afero.Fs, pathToPkgJSON string) (string, error)

RetrieveProjectName returns the project name as string parsing the package.json file.

func Sum

func Sum(x int, y int) int

Sum adds two integer values.

func ToBasePath added in v0.4.0

func ToBasePath(fullpath string, replace string) string

ToBasePath returns a copy of string replacing all occurrences for a string with trailing slash.

func ToLibFile added in v0.5.4

func ToLibFile(txt string) string

ToLibFile returns a string a valid lib filename example: ToLibFile("category") returns 'apiCategory.ts'.

func ToMDFile

func ToMDFile(txt string, uppercase bool) string

ToMDFile returns a string with .md extension example: ToMDFile("getting started", false) returns 'getting-started.md'. example: ToMDFile("getting started", true) returns 'GETTING-STARTED.md'.

func ToSlug added in v0.5.4

func ToSlug(txt string) string

ToSlug returns a copy of string with lowercase replacing "_" and whitespaces with "-" example: ToSlug("New Resource") returns new-resource.

func ToSnakeCase added in v0.8.3

func ToSnakeCase(txt string) string

ToSnakeCase returns a copy of string with lowercase replacing "-" and whitespaces with "_" example: ToSnakeCase("New Resource") returns new_resource.

func ToTitle

func ToTitle(txt string) string

ToTitle replace all '-' char with a white space and returns a copy of string s with all letters of string whose begin words mapped to their title case.

func ToURL

func ToURL(txt string) string

ToURL returns a trimmed string with '/' as prefix.

func ToVariableName added in v0.5.4

func ToVariableName(txt string) string

ToVariableName returns a copy of string to be used as variable name.

func Today

func Today() string

Today returns the current date as formatted string "DD-ShortMonth-YYYY".

func Trimmed

func Trimmed(txt string) string

Trimmed strips away '"' from a string.

Types

type GitHubRepo added in v0.8.0

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

GitHubRepo is the struct representing a GitHub repository

func NewGitHubURLParser added in v0.8.0

func NewGitHubURLParser(input string) (*GitHubRepo, error)

NewGitHubURLParser takes a github url and returns the repository info as GitHubRepo struct

func (*GitHubRepo) GetHost added in v0.8.0

func (gh *GitHubRepo) GetHost() string

GetHost returns the host as string

func (*GitHubRepo) GetRepo added in v0.8.0

func (gh *GitHubRepo) GetRepo() string

GetRepo returns the repo name as string

func (*GitHubRepo) GetUser added in v0.8.0

func (gh *GitHubRepo) GetUser() string

GetUser returns the repo's owner as string

Jump to

Keyboard shortcuts

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