Skip to content

Function: toUniqueSlug()

toUniqueSlug(value, options?): string

Slugify value (using the standard toIdentifierWithOptions tokenizer + delimiter rules) and always suffix a short deterministic hash. Use when you need a stable, slugified id that is guaranteed to be unique across descriptions sharing the same leading tokens (tool ids, cache keys, etc.).

Behaviour differs from toIdentifierWithOptions({ maxLength, truncateStrategy: "hash" }): that helper only appends a hash when the slug overflows maxLength. This helper appends a hash unconditionally so the result is collision-resistant even for short inputs. The hash is computed over the raw value so two descriptions producing the same slug still get different ids.

string

Source string (typically a tool/agent description).

string

Token separator (default "_").

string

Prefix used when the slug is empty (e.g. punctuation-only input). Default "id".

number

Length of the suffix produced by fnvHashWithOptions (Crockford-style base-32 alphabet, max 7 chars). Default 6.

number

Cap on the slug portion (the part before the hash). Default 32.

string