slug

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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 slug derives DNS-1123-compatible identifiers from free-text display names, with deterministic collision suffixes.

Index

Constants

View Source
const MaxLen = 63

Variables

This section is empty.

Functions

func From

func From(displayName string) string

From slugifies a free-text display name. Lowercases, replaces runs of non-[a-z0-9] with a single dash, trims leading/trailing dashes, truncates to MaxLen. Returns "" when the input has no usable characters; callers should treat empty as an error.

func FromPrefix added in v0.3.0

func FromPrefix(s string) string

FromPrefix normalizes the literal prefix of a wildcard pattern. Unlike From it keeps the boundary dash when the raw prefix ends mid-separator ("claude-fable-5[" → "claude-fable-5-"), so prefix matching against From-normalized keys stays boundary-accurate ("claude-fable-5[*]" must not match "claude-fable-50-foo"). No MaxLen truncation — patterns are validated, not minted.

func FromSuffix added in v0.3.0

func FromSuffix(s string) string

FromSuffix normalizes the literal suffix of a wildcard pattern: the mirror of FromPrefix — keeps a leading boundary dash (":acme" → "-acme"), trims trailing separators ("]" → "").

func Unique

func Unique(base string, exists func(candidate string) bool) string

Unique returns base if exists(base) is false; otherwise base-2, base-3, … until exists returns false. Callers own the uniqueness scope (per-kind index).

func Valid

func Valid(s string) bool

Valid reports whether s is a legal slug (DNS-1123 label, ≤63 chars).

func WithSuffix

func WithSuffix(base string, n int) string

WithSuffix appends "-N" to base, ensuring the result fits in MaxLen by trimming base. N ≥ 2 (callers iterate from 2).

Types

This section is empty.

Jump to

Keyboard shortcuts

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