helpers

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMap

func CopyMap[T any](m map[string]T) (result map[string]T)

CopyMap returns a copy of a map. TODO generalise keys

func If

func If[T any](b bool, trueVal, falseVal T) T

func IsDateString

func IsDateString(date string) bool

IsDateString returns true if the `data` is formatted like YYYY-MM-DD.

func LaunchBrowser

func LaunchBrowser(url string) error

LaunchBrowser launches the browser at the url address. Waits till launch completed. Credit: https://stackoverflow.com/a/39324149/1136455

func MergeMap

func MergeMap[T any](dst map[string]T, maps ...map[string]T)

MergeMap merges maps into dst map. TODO generalise keys

func NormalizeNewlines

func NormalizeNewlines(s string) (result string)

NormalizeNewlines converts \r\n (Window) and \n (Mac OS) line terminations to \n (UNIX) termination.

func ParseDateOrOffset added in v0.2.0

func ParseDateOrOffset(date string, fromDate string) (string, error)

ParseDateOrOffset attempts to parse the `date` string which can be a YYYY-MM-DD formatted date or an integer offset (0=today, -1=yesterday, ...). The `fromDate` is a YYYY-MM-DD date string representing the date offset origin.

func ParseDateString

func ParseDateString(text string, loc *time.Location) (time.Time, error)

ParseDateString parses converts a date string to a time.Time. If timezone is not specified Local is assumed.

func SortedMapKeys

func SortedMapKeys[K constraints.Ordered, V any](m map[K]V) (res []K)

SortedMapKeys returns a sorted array of map keys. TODO tests

func TimeNowString

func TimeNowString() string

TimeNowString returns the current time as a string.

func TodaysDate

func TodaysDate() string

TodaysDate returns the current date as a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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