tools

package
v0.0.0-...-4fcd703 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 36 Imported by: 0 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

Package tools holds the pure logic behind every orion tool, kept free of UI code so it is easy to test.

Index

Constants

View Source
const DefaultZones = "UTC, New York, Los Angeles, London, Paris, Tokyo, Sydney"

Variables

View Source
var BaseEncodings = []string{"base64", "base64url", "base32", "base32hex"}

Base64 encodings, in option order.

View Source
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.

View Source
var CompressFormats = []string{"auto", "gzip", "zlib", "deflate"}

CompressFormats in option order. Index 0 (auto) only applies to decompress.

View Source
var ContextSizes = []int{128_000, 200_000, 1_000_000}

ContextSizes in option order.

View Source
var DateDialects = []string{"Go", "strftime", "Java / date-fns (LDML)", "Moment.js / Day.js", "PHP"}

DateDialects in option order.

View Source
var JWTAlgs = []string{"HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "ES256", "ES384", "EdDSA"}

JWTAlgs in option order.

View Source
var LoremKinds = []string{"paragraphs", "sentences", "words", "names", "emails", "urls", "titles", "usernames"}

Lorem kinds, in option order.

Functions

func CRC

func CRC(p crcParams, data []byte) uint64

CRC computes a CRC of width ≤ 64 bit by bit using Rocksoft parameters.

func CalendarDiff

func CalendarDiff(a, b time.Time) (y, m, d int, rest time.Duration)

CalendarDiff returns whole years, months, days and the remaining duration from a to b (a <= b).

func Contrast

func Contrast(a, b RGBA) float64

Contrast is the WCAG contrast ratio between two colors.

func ConvertCase

func ConvertCase(s, name string) string

ConvertCase converts s to the named case.

func EncodeJSON

func EncodeJSON(v any, indent string) string

EncodeJSON writes v; indent "" means minified.

func EncodeURIComponent

func EncodeURIComponent(s string) string

EncodeURIComponent matches JavaScript's encodeURIComponent.

func FormatNum

func FormatNum(v float64) string

FormatNum prints a float compactly without exponent for everyday magnitudes.

func HexDump

func HexDump(b []byte) string

HexDump renders up to 4 KiB of bytes as a classic hex dump.

func Humanize

func Humanize(d time.Duration) string

Humanize renders a duration like "2 days 3 hours".

func Luhn

func Luhn(d string) bool

Luhn reports whether a digit string passes the Luhn check.

func LuhnCheckDigit

func LuhnCheckDigit(d string) int

LuhnCheckDigit returns the digit to append to d.

func ModeString

func ModeString(m uint32) string

ModeString renders rwxr-xr-x with setuid/setgid/sticky.

func NewSIN

func NewSIN(r *rand.Rand, temporary bool) string

NewSIN returns a Luhn-valid 9-digit Canadian SIN.

func ParseJSON

func ParseJSON(s string) (any, error)

ParseJSON parses JSON keeping object key order. Numbers stay json.Number.

func ParseJSONOrYAML

func ParseJSONOrYAML(s string) (any, error)

ParseJSONOrYAML accepts JSON, falling back to YAML.

func ParseMode

func ParseMode(s string, base uint32) (uint32, string, error)

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

func ParseTime(s string, now time.Time, loc *time.Location) (t time.Time, unit string, err error)

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 PatchJSON

func PatchJSON(ops []PatchOp) string

PatchJSON renders ops as an RFC 6902 JSON Patch document.

func ResolveZone

func ResolveZone(s string, local *time.Location) (*time.Location, string, error)

ResolveZone accepts IANA names (any case), abbreviations, cities, "local" and offsets like UTC+5:30.

func Slug

func Slug(s string) string

Slug makes a URL slug, folding common accents to ASCII.

func SortKeys

func SortKeys(v any)

SortKeys recursively sorts object keys.

func SplitWords

func SplitWords(s string) []string

SplitWords splits identifiers and prose into words: "parseHTTPRequest v2" → parse, HTTP, Request, v2.

func ToXML

func ToXML(v any, indent string) string

ToXML converts parsed JSON to XML. Arrays repeat the parent element name.

func ToYAML

func ToYAML(v any) (string, error)

ToYAML converts parsed JSON to YAML keeping key order.

func ValidSIN

func ValidSIN(s string) bool

ValidSIN checks length and the Luhn checksum (spaces and dashes ignored).

func Weekdays

func Weekdays(a, b time.Time) int

Weekdays counts Monday–Friday days in [a, b).

Types

type Object

type Object struct {
	Keys []string
	M    map[string]any
}

Object is a JSON object that remembers key order.

type PatchOp

type PatchOp struct {
	Op    string
	Path  string
	Value any
	Old   any
}

PatchOp is one RFC 6902 operation.

func DiffJSON

func DiffJSON(a, b any, arrayKey string) []PatchOp

DiffJSON returns the operations that turn a into b. If arrayKey is set, arrays whose items are all objects with that key are matched by it.

type RGBA

type RGBA struct{ R, G, B, A float64 }

RGBA is a color with channels in 0..1.

func ParseColor

func ParseColor(s string) (RGBA, error)

ParseColor reads hex, rgb(), hsl(), hwb(), hsv(), oklch(), "r, g, b" and CSS names.

func (RGBA) HSL

func (c RGBA) HSL() (float64, float64, float64)

HSL returns hue (deg), saturation and lightness (0..1).

func (RGBA) HSV

func (c RGBA) HSV() (float64, float64, float64)

HSV returns hue (deg), saturation and value (0..1).

func (RGBA) Hex

func (c RGBA) Hex() string

Hex renders #rrggbb (or #rrggbbaa when translucent).

func (RGBA) Luminance

func (c RGBA) Luminance() float64

Luminance is WCAG relative luminance.

func (RGBA) OKLCH

func (c RGBA) OKLCH() (float64, float64, float64)

OKLCH returns lightness (0..1), chroma and hue (deg).

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

func (*Redactor) Redact

func (r *Redactor) Redact(s string) (string, map[string]int)

Redact replaces secrets and personal data with stable placeholders.

func (*Redactor) Restore

func (r *Redactor) Restore(s string) (string, int)

Restore puts original values back in place of known placeholders.

func (*Redactor) Run

func (r *Redactor) Run(in string, mode int) (Result, error)

Run implements the tool. mode 0 redact, 1 restore.

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

func AIClean(s string, quotes, markdown, citations bool, dashes int) (Result, error)

AIClean removes invisible characters and AI chat artefacts. dashes: 0 keep, 1 em/en dash → hyphen, 2 em dash → comma.

func BaseCodec

func BaseCodec(in string, enc int, decode bool) (Result, error)

BaseCodec encodes or decodes text. Decoding ignores whitespace, missing padding and a data: URI prefix.

func Cases

func Cases(s string, only int) Result

Cases converts every line of s into every case. If only is >= 0, output just that case (for copying).

func Checksum

func Checksum(in string, inputHex bool) (Result, error)

Checksum: inputHex reads the input as hex bytes.

func Chmod

func Chmod(in string, baseOpt int) (Result, error)

Chmod implements the chmod calculator.

func ColorTool

func ColorTool(in string) (Result, error)

ColorTool renders conversions, contrast, shades and harmonies.

func Compress

func Compress(in string, mode, format int, outHex bool) (Result, error)

Compress: mode 0 decompress, 1 compress. outHex selects hex output for compress.

func DateDiff

func DateDiff(from, to string, now time.Time, loc *time.Location) (Result, error)

DateDiff implements the date difference tool.

func DateFormat

func DateFormat(in string, from int, now time.Time) (Result, error)

DateFormat translates a format string from one dialect into all the others.

func HTMLToJSX

func HTMLToJSX(src string) (Result, error)

HTMLToJSX converts an HTML fragment to JSX.

func JSONDiff

func JSONDiff(a, b, key string, mode int) (Result, error)

JSONDiff implements the JSON diff tool. mode 0 = change list, 1 = JSON Patch.

func JSONView

func JSONView(src, query string, format int, sortKeys bool, indentOpt int) (Result, error)

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

func JWTDecode(token, key string, now time.Time) (Result, error)

JWTDecode decodes a token and, if key is given, verifies its signature. key is an HMAC secret or a PEM public key / certificate.

func JWTSign

func JWTSign(payload, key string, alg int) (Result, error)

JWTSign signs a JSON payload. exp/iat are left as given.

func Lorem

func Lorem(countStr string, kind int, asJSON bool, seed uint64) (Result, error)

Lorem generates count items of the given kind. Starts with "Lorem ipsum" for text kinds.

func R

func R(out string) Result

func Regex

func Regex(pattern, text, repl string, ci, multi, dotall bool) (Result, error)

Regex implements the regex tester (Go RE2 syntax).

func SINs

func SINs(countStr string, format int, seed uint64) (Result, error)

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

func TextCompare(a, b string, gran int, ignoreWS, ignoreCase bool) (Result, error)

TextCompare diffs a and b. gran: 0 lines, 1 words, 2 characters.

func TimeZones

func TimeZones(when, from, targets string, now time.Time, local *time.Location) (Result, error)

TimeZones converts a time in one zone to a list of others.

func Timestamp

func Timestamp(in string, now time.Time, loc *time.Location) (Result, error)

Timestamp implements the timestamp converter.

func TokenCount

func TokenCount(s string, ctx int) (Result, error)

TokenCount counts tokens. OpenAI counts are exact (tiktoken); others are rough character-based estimates and are labelled as such.

func URLTool

func URLTool(in string, mode int) (Result, error)

URLTool: mode 0 parse, 1 encode, 2 decode.

func Units

func Units(in string) (Result, error)

Units converts "10 km" (all units in the category) or "10 km to mi".

Jump to

Keyboard shortcuts

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