strdist

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package strdist provides small string-distance helpers for typo-tolerant CLI suggestions ("did you mean X?"). Cross-cutting and project-agnostic: consumers are tools that take a name argument and want to self-correct a near-miss instead of failing silently (e.g. `sf composer show <pkg>`, flag-typo hints).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Levenshtein

func Levenshtein(a, b string) int

Levenshtein returns the edit distance between a and b (insert/delete/substitute, cost 1 each). Operates on runes, so it is correct for non-ASCII input.

func Nearest

func Nearest(target string, candidates []string) (best string, ok bool)

Nearest returns the candidate closest to target under a tolerance scaled to target length (≤ ⌈len/3⌉, min 1) — close enough to be a likely typo, not an unrelated word. Comparison is case-insensitive. ok is false when no candidate is within tolerance (or candidates is empty), so callers can fall back to a generic hint. Ties resolve to the first candidate in iteration order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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