utils

package
v0.0.0-...-ab933d4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package utils are utils, duh

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToItems

func ConvertToItems[S any](
	sourceSlice []S,
	mapper func(item S) list.Item,
) []list.Item

ConvertToItems converts a slice of source items (sourceSlice) of any type S into a slice of list.Item using a custom mapping function.

S represents the type of the source items in the input slice.

The mapper function is responsible for transforming a single source item (S) into a list.Item.

It returns a new slice of list.Item with the same length as the source slice.

func GetImagePreview

func GetImagePreview(img image.Image, imageSize int) string

GetImagePreview was shamelessly copied from https://github.com/savedra1/clipse

func GetStreamPreview

func GetStreamPreview(stream helix.Stream, previewSize int) (string, error)

GetStreamPreview fetches a thumbnail image from a stream and generates a terminal-based preview of it.

It takes a helix.Stream, which contains the stream details including the `ThumbnailURL` template, and a desired 'previewSize' (the target width for the terminal preview).

The `ThumbnailURL` template is modified to request a 320x180 default Twitch's image size before fetching. The image data is then decoded and passed to GetImagePreview for terminal rendering.

It returns the ANSI-encoded string for the terminal preview or an [error] if fetching or decoding the image fails, or if the HTTP request is unsuccessful.

func Humanize

func Humanize(number int) string

Humanize converts a large integer into a concise, human-readable string representation using suffixes:

K for thousands (1,000)

M for millions (1,000,000)

B for billions (1,000,000,000)

The value is rounded to the nearest whole number before applying the suffix. For numbers less than 1000, the original number is returned as a string.

Examples:

999 => 999 1000 => 1K 1500 => 2K 50000 => 50K 500000 => 500K 1000000 => 1M 1500000 => 2M 500000000 => 500M 1000000000 => 1B 1500000000 => 2B

func Paginate

func Paginate[T any](
	request func(after string) ([]T, string, error),
) ([]T, error)

Paginate fetches all pages of resources of type T by repeatedly calling the provided request function until no more pages are available.

The type parameter T represents the type of the items being paginated.

The request function takes a string, 'after', which is the cursor for the next page, and returns a slice of items ([]T), the next cursor string, and an error. The initial call to request should receive an empty string ("") for 'after'. Pagination stops when the request function returns an empty string for the next cursor.

It returns a single slice containing all fetched items and an error if any request fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

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