Documentation
¶
Index ¶
- Constants
- func AppendUnique(s []string, v string) []string
- func BaseUrl(urlStr string) string
- func Cleanup(s string) string
- func CleanupInline(s string) string
- func CleanupLang(lang string) string
- func Deduplicate[E comparable](s []E) []E
- func DomainZone(urlStr string) string
- func FindFloat(val any) float64
- func FindInt(val any) int
- func FindNumber(str string) *float64
- func FirstMetaContent(el *goquery.Selection, names ...string) (string, bool)
- func FormatFraction(f float64) string
- func GetMetaContent(el *goquery.Selection, key, name string) (string, bool)
- func HostAlias(urlStr string) string
- func Hostname(urlStr string) string
- func IsAbsolute(urlStr string) bool
- func LanguageByDomain(tld string) (string, bool)
- func Parse8601Duration(str string) time.Duration
- func ParseDate(str string) (*time.Time, bool)
- func ParseDuration(str string) (time.Duration, bool)
- func ParseFloat(str string) (float64, error)
- func ParseFraction(str string) (float64, error)
- func ParseInt(str string) (int, error)
- func ParseKilocalories(str string) *float64
- func ParseMass(str string, target Unit) *float64
- func RecoverPanic(label string, errp *error)
- func RemoveDoubleSpace(str string) string
- func RemoveNewLines(s string) string
- func RemoveSpaces(s string) string
- func RemoveTrailingSlash(urlStr string) string
- func SplitParagraphs(s string) []string
- func SplitTitle(title string) []string
- func ToAbsoluteUrl(base *url.URL, urlStr string) string
- func TrimZeroWidthSpaces(s string) string
- func Unquote(s string) string
- func UrlMatchesPathPattern(rawUrl, pattern string, targetHost ...string) bool
- type RequestConfig
- type RequestResult
- type Unit
Constants ¶
const Fractions = "¼½¾⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞"
Variables ¶
This section is empty.
Functions ¶
func AppendUnique ¶
func CleanupInline ¶
func CleanupLang ¶
func Deduplicate ¶
func Deduplicate[E comparable](s []E) []E
func DomainZone ¶
func FindNumber ¶
func FirstMetaContent ¶ added in v0.17.0
FirstMetaContent returns the content attribute of the first matching meta-element from a list of identifiers.
func FormatFraction ¶
func GetMetaContent ¶ added in v0.17.0
GetMetaContent retrieves the "content" attribute of a meta tag matching the specified key and name in the selection.
func IsAbsolute ¶
func LanguageByDomain ¶
func Parse8601Duration ¶ added in v0.3.0
func ParseFloat ¶
func ParseFraction ¶
func ParseKilocalories ¶ added in v0.20.0
ParseKilocalories parses str as an energy value and converts it to kilocalories. Returns nil if str has a recognized unit that isn't energy (e.g. "12 g").
func ParseMass ¶ added in v0.20.0
ParseMass parses str as a mass and converts it to target (e.g. UnitGram, UnitMilligram). Returns nil if str has a recognized unit that isn't a mass (e.g. "12 kcal") - wrong scale entirely, so there's no sensible number to fall back on.
func RecoverPanic ¶ added in v0.20.0
RecoverPanic recovers a panic in the deferring function and converts it into an error assigned to *errp, logging the stack trace under label.
Must be used as `defer utils.RecoverPanic(label, &err)` in a function with a named error return — recover() only stops a panic when called directly by the deferred function itself, so wrapping this call in another closure (e.g. `defer func() { utils.RecoverPanic(...) }()`) will not catch anything.
func RemoveDoubleSpace ¶
func RemoveNewLines ¶
func RemoveSpaces ¶
func RemoveTrailingSlash ¶
func SplitParagraphs ¶
func SplitTitle ¶
func TrimZeroWidthSpaces ¶
func UrlMatchesPathPattern ¶ added in v0.17.0
UrlMatchesPathPattern checks if rawUrl's path starts with pattern. If targetHost is supplied, absolute URLs with a non-matching host are rejected.
Types ¶
type RequestConfig ¶ added in v0.16.0
type RequestResult ¶ added in v0.20.0
func ExecuteRequest ¶ added in v0.16.0
func ExecuteRequest(config RequestConfig, options model.RequestOptions) (*RequestResult, error)
type Unit ¶ added in v0.20.0
type Unit string
Unit is a recognized mass or energy unit found alongside a number.
Only SI/scientific abbreviations are recognized (g, mg, kcal, kJ, г, мг, ...), not translated unit words, since these are used verbatim across most languages' nutrition labels. Scripts/words not listed here are left unrecognized and fall back to a bare number.
func FindNumberWithUnit ¶ added in v0.20.0
FindNumberWithUnit extracts the first number in str and its unit, if recognized. unit is "" when none is found, meaning the caller should assume its own default.