strs

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Text helpers every part of icebath shares: cuts by characters, sentences, numbers, sizes and lengths of time in words, first filled values, sets and random tokens

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func About

func About(length time.Duration) string

Length of time in words rounded to the nearest of the unit a person reads it in, such as how long a wait lasts or is left: seconds under two minutes, minutes under two hours, hours under two days and days past that, at least a second

func Agreeing

func Agreeing(n int, noun, one, many string) string

Count of things named in the singular with the verb after it agreeing, the verb given for one and for several: 1 session matches, 2 sessions match

func And

func And(items []string) string

Items as a person lists them, the last after "and": a, b and c

func AndMore

func AndMore(items []string, parts int) string

Items as a person lists them in at most the parts given: all of them when they fit, else the first ones and how many more, such as a, b and 6 more

func Capital

func Capital(text string) string

Text that starts a sentence: its first letter a capital, unless its first word is a name that keeps its own case, such as icebath or openWakeWord

func Clip

func Clip(s string, n int) string

First n characters of a text with an ellipsis after them when it was longer

func CompareVersions

func CompareVersions(a, b string) int

Order of two versions by their sort keys: their numbers compared as numbers, so 1.10 comes after 1.9. A word where the other has a number or has ended starts a prerelease, which comes before its release, so 1.0rc1 comes before 1.0 and 1.0.1; zeros past the end of the other add nothing, so 1.2 is 1.2.0

func Count

func Count(n int, noun string) string

Count of things named in the singular: 1 session, 2 sessions

func Counted

func Counted(n float64, what string) string

Number and the word for what it counts, given in the plural and said in the singular for exactly one: 1 call, 50,000 characters

func Deref

func Deref(p *string) string

Text a pointer holds, empty for nil

func Filled

func Filled(texts ...string) string

First of the texts that is not blank, trimmed; empty when every one is

func First

func First(items []string) string

First of the items, empty when there are none

func Fit

func Fit(s string, n int, tail string) string

Text in at most n characters, such as a preview with room for so many: a longer one cut, the spaces the cut leaves at its end trimmed, and tail, such as … or ..., ending it within the n

func Full

func Full(text string) string

Text as a sentence of its own: trimmed, its first letter a capital as Capital gives it, and an end mark as Sentence gives it; empty for none

func Head(s string, n int) string

First n characters of a text, its bytes kept as they are

func Last

func Last(text string) string

Last line of a text that is not blank, trimmed, such as what a program printed last; empty when every line is blank

func Line

func Line(text string) string

Text on one line: every run of spaces and line breaks in it one space, none at its ends

func List

func List(values []string) []string

The list, empty rather than nil so JSON writes it as [] and not null

func Lower

func Lower(text string) string

Text that reads inside a sentence: its first letter in lower case, unless its first word is an acronym or a name with capitals of its own, such as MCP or iOS

func Middle

func Middle(text string, head, tail int, mark func(omitted, total int) string) string

Text keeping head characters of its start and tail of its end once it is longer than both, with the mark between them that mark makes of how many characters were left out of how many, such as a notice that the middle of a long output was cut

func MinorVersion

func MinorVersion(version string) (string, bool)

Major and minor of a version, such as 3.12 of 3.12.4, false when it has fewer than two numbers

func Nullable

func Nullable(text string) any

Text as a value JSON writes as null when it is empty

func Number

func Number(n float64) string

Number in digits grouped in thousands, with as many decimals as it has and no more than three

func OnOff

func OnOff(on bool) string

Word of a switch: On or Off

func Opening

func Opening(text string) string

First sentence of a text, on one line: the text up to the first mark that ends a sentence with more after it, such as what a refusal says before what it tells the agent to do; the whole line when it has one sentence

func Or

func Or(items []string) string

Items as a person lists them, the last after "or": a, b or c

func Ordinal

func Ordinal(n int) string

Place in an order as a number with its ending: 1st, 2nd, 3rd, 4th, 11th, 21st

func Place

func Place(n int) string

Place in a list as a person says it inside a sentence: first, second and third, then as Ordinal writes it, such as 4th or 21st

func Plural

func Plural(word string) string

Word for several of what the singular names

func Quote

func Quote(words ...string) string

Words as a POSIX shell would read them back, one or a whole command line: a word with anything in it a shell reads as more than itself, or with nothing in it, quoted

func Random

func Random(n int) string

Hex digits of n random bytes

func Rounded

func Rounded(length time.Duration) string

Length of time in words rounded down to its largest whole unit, such as how long ago something was: 45 seconds, 3 minutes, 2 days; under a second for less

func Sentence

func Sentence(text string) string

Text that ends as a sentence: trimmed, with a period added when it ends in no mark of its own; empty for none

func Set

func Set(items ...string) map[string]bool

Set of the items

func Shell

func Shell(line string) ([]string, error)

Words of a command line split as a POSIX shell splits them, honoring quotes and backslashes: a backslash takes the next character as it is, inside double quotes only a $, a backquote, a double quote or another backslash, any other keeping its backslash, and a backslash before the end of a line joins the line to the next; an error, said for a person, when a quote or a backslash at the end is left open

func Singular

func Singular(word string) string

Word for one of what the plural names: a short unit such as MB or ms is left as it is

func Size

func Size(n float64) string

Count of bytes in the largest unit that fits, the units of 1024 for a count they divide and of 1000 for any other: 512 bytes, 1.5 KB, 5 MB

func Span

func Span(length time.Duration) string

Length of time in words, in the largest unit that divides it: 1 hour, 90 minutes, 1.5 seconds

func Strftime

func Strftime(t time.Time, format string) string

A time as C's strftime writes it under the C locale, as Python's strftime gives it and as a person writes a format such as %H:%M: %Y %y %m %d %e %H %I %l %M %S %p %b %h %B %a %A %j %w %Z %z %F %T and %%, a - after the % leaving a number unpadded; any other % pair is kept

func Tail

func Tail(s string, n int) string

Last n characters of a text, its bytes kept as they are

func Thousands

func Thousands[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](n T) string

Whole number with commas between its thousands

func Token

func Token(n int) string

N random bytes as unpadded URL safe base64, the shape of a state, verifier or token handed out

func Typed

func Typed(word string) string

Word as typed, on one line and cut to what a sentence holds, for an answer that names what it could not take

func Unique

func Unique(items []string) []string

Items without their repeats, each where it first came, never nil

Types

type Word

type Word struct {
	Text       string
	Start, End int
}

A word of a line as a person types it in a chat, and where it lies in the line with its quotes

func Chat

func Chat(line string) ([]Word, error)

Words of a line as a person types them in a chat: split at spaces and line breaks, a run in single or double quotes kept whole. A backslash keeps the quote, backslash or space after it as it is and joins a line to the next before a line break, and is itself before anything else, as in a path of Windows; inside double quotes it keeps a quote, a backslash, a $ or a backquote. A quote right after a letter or a digit of a word is the word's own, as in don't or Nick's, and so is a single quote between two letters inside single quotes, so a name such as Nick's site reads as typed and words Quote wrote read back as they were. An error a person reads for a quote never closed or a backslash ending the line

Jump to

Keyboard shortcuts

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