Produces a safe identifier by replacing disallowed characters with hyphens, collapsing consecutive hyphens, trimming edge hyphens, and defaulting to "id" for null, whitespace, or empty results. Optionally appends a short deterministic 4-character lowercase hex hash (prefixed with a hyphen) derived from the original input to ensure uniqueness.
Parameters
inputThe source string to convert into a safe identifier.appendHashIf true, appends a short deterministic 4-character lowercase hex hash (prefixed with a hyphen).
Returns
The sanitized identifier; if appendHash is true the value is suffixed with "-" and a 4-character lowercase hex hash.