Documentation
¶
Overview ¶
Package tools holds the pure logic behind every orion tool, kept free of UI code so it is easy to test.
Index ¶
- Constants
- Variables
- func CRC(p crcParams, data []byte) uint64
- func CalendarDiff(a, b time.Time) (y, m, d int, rest time.Duration)
- func Contrast(a, b RGBA) float64
- func ConvertCase(s, name string) string
- func EncodeJSON(v any, indent string) string
- func EncodeURIComponent(s string) string
- func FormatNum(v float64) string
- func HexDump(b []byte) string
- func Humanize(d time.Duration) string
- func Luhn(d string) bool
- func LuhnCheckDigit(d string) int
- func ModeString(m uint32) string
- func NewSIN(r *rand.Rand, temporary bool) string
- func ParseJSON(s string) (any, error)
- func ParseJSONOrYAML(s string) (any, error)
- func ParseMode(s string, base uint32) (uint32, string, error)
- func ParseTime(s string, now time.Time, loc *time.Location) (t time.Time, unit string, err error)
- func PatchJSON(ops []PatchOp) string
- func ResolveZone(s string, local *time.Location) (*time.Location, string, error)
- func Slug(s string) string
- func SortKeys(v any)
- func SplitWords(s string) []string
- func ToXML(v any, indent string) string
- func ToYAML(v any) (string, error)
- func ValidSIN(s string) bool
- func Weekdays(a, b time.Time) int
- type Object
- type PatchOp
- type RGBA
- type Redactor
- type Result
- func AIClean(s string, quotes, markdown, citations bool, dashes int) (Result, error)
- func BaseCodec(in string, enc int, decode bool) (Result, error)
- func Cases(s string, only int) Result
- func Checksum(in string, inputHex bool) (Result, error)
- func Chmod(in string, baseOpt int) (Result, error)
- func ColorTool(in string) (Result, error)
- func Compress(in string, mode, format int, outHex bool) (Result, error)
- func DateDiff(from, to string, now time.Time, loc *time.Location) (Result, error)
- func DateFormat(in string, from int, now time.Time) (Result, error)
- func HTMLToJSX(src string) (Result, error)
- func JSONDiff(a, b, key string, mode int) (Result, error)
- func JSONView(src, query string, format int, sortKeys bool, indentOpt int) (Result, error)
- func JWTDecode(token, key string, now time.Time) (Result, error)
- func JWTSign(payload, key string, alg int) (Result, error)
- func Lorem(countStr string, kind int, asJSON bool, seed uint64) (Result, error)
- func R(out string) Result
- func Regex(pattern, text, repl string, ci, multi, dotall bool) (Result, error)
- func SINs(countStr string, format int, seed uint64) (Result, error)
- func TextCompare(a, b string, gran int, ignoreWS, ignoreCase bool) (Result, error)
- func TimeZones(when, from, targets string, now time.Time, local *time.Location) (Result, error)
- func Timestamp(in string, now time.Time, loc *time.Location) (Result, error)
- func TokenCount(s string, ctx int) (Result, error)
- func URLTool(in string, mode int) (Result, error)
- func Units(in string) (Result, error)
Constants ¶
const DefaultZones = "UTC, New York, Los Angeles, London, Paris, Tokyo, Sydney"
Variables ¶
var BaseEncodings = []string{"base64", "base64url", "base32", "base32hex"}
Base64 encodings, in option order.
var CaseNames = []string{"camelCase", "PascalCase", "snake_case", "SCREAMING_SNAKE", "kebab-case", "Train-Case", "dot.case", "path/case", "Title Case", "Sentence case", "lower case", "UPPER CASE", "slug"}
CaseNames lists the conversions in output order.
var CompressFormats = []string{"auto", "gzip", "zlib", "deflate"}
CompressFormats in option order. Index 0 (auto) only applies to decompress.
var ContextSizes = []int{128_000, 200_000, 1_000_000}
ContextSizes in option order.
var DateDialects = []string{"Go", "strftime", "Java / date-fns (LDML)", "Moment.js / Day.js", "PHP"}
DateDialects in option order.
var JWTAlgs = []string{"HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "ES256", "ES384", "EdDSA"}
JWTAlgs in option order.
var LoremKinds = []string{"paragraphs", "sentences", "words", "names", "emails", "urls", "titles", "usernames"}
Lorem kinds, in option order.
Functions ¶
func CalendarDiff ¶
CalendarDiff returns whole years, months, days and the remaining duration from a to b (a <= b).
func ConvertCase ¶
ConvertCase converts s to the named case.
func EncodeJSON ¶
EncodeJSON writes v; indent "" means minified.
func EncodeURIComponent ¶
EncodeURIComponent matches JavaScript's encodeURIComponent.
func LuhnCheckDigit ¶
LuhnCheckDigit returns the digit to append to d.
func ModeString ¶
ModeString renders rwxr-xr-x with setuid/setgid/sticky.
func ParseJSONOrYAML ¶
ParseJSONOrYAML accepts JSON, falling back to YAML.
func ParseMode ¶
ParseMode reads octal ("755", "0644", "4755"), ls-style ("-rwxr-xr-x", "rwsr-xr-x") or symbolic expressions ("u+x,go-w", "a=r") applied to base.
func ParseTime ¶
ParseTime understands "now", unix timestamps (s/ms/µs/ns), many date formats, clock times (today) and trailing offsets like "now - 1d 3h" or "2026-01-01 + 2w". unit reports how a numeric input was read.
func ResolveZone ¶
ResolveZone accepts IANA names (any case), abbreviations, cities, "local" and offsets like UTC+5:30.
func SplitWords ¶
SplitWords splits identifiers and prose into words: "parseHTTPRequest v2" → parse, HTTP, Request, v2.
Types ¶
type RGBA ¶
type RGBA struct{ R, G, B, A float64 }
RGBA is a color with channels in 0..1.
func ParseColor ¶
ParseColor reads hex, rgb(), hsl(), hwb(), hsv(), oklch(), "r, g, b" and CSS names.
type Redactor ¶
type Redactor struct {
// contains filtered or unexported fields
}
Redactor keeps the placeholder ↔ value map so a reply can be restored.
func NewRedactor ¶
func NewRedactor() *Redactor
type Result ¶
type Result struct {
Out string // shown in the output pane (may contain ANSI styling)
Info string // short status shown next to the output label
Copy string // what ctrl+y copies; Out (stripped of styling) when empty
}
Result is what a tool produces for one set of inputs.
func AIClean ¶
AIClean removes invisible characters and AI chat artefacts. dashes: 0 keep, 1 em/en dash → hyphen, 2 em dash → comma.
func BaseCodec ¶
BaseCodec encodes or decodes text. Decoding ignores whitespace, missing padding and a data: URI prefix.
func Cases ¶
Cases converts every line of s into every case. If only is >= 0, output just that case (for copying).
func DateFormat ¶
DateFormat translates a format string from one dialect into all the others.
func JSONView ¶
JSONView implements the JSON viewer tool. format: 0 pretty, 1 minify, 2 yaml, 3 xml. indent: 0 two spaces, 1 four, 2 tab.
func JWTDecode ¶
JWTDecode decodes a token and, if key is given, verifies its signature. key is an HMAC secret or a PEM public key / certificate.
func Lorem ¶
Lorem generates count items of the given kind. Starts with "Lorem ipsum" for text kinds.
func SINs ¶
SINs generates count regular and count temporary test SINs, shown side by side. format: 0 "123 456 782", 1 "123-456-782", 2 "123456782". ctrl+y copies the two lists one after the other.
func TextCompare ¶
TextCompare diffs a and b. gran: 0 lines, 1 words, 2 characters.
func TokenCount ¶
TokenCount counts tokens. OpenAI counts are exact (tiktoken); others are rough character-based estimates and are labelled as such.