import { randomId } from 'ngwr/utils';
const id = randomId('wr-input'); // 'wr-input-a8f2bx1k9q4z'
const short = randomId('wr-input', 6); // 'wr-input-h7m4k2'randomId
Short prefixed random id, for <label for> and aria-describedby pairs.
Usage
API
| Name | Description | Type | Default |
|---|---|---|---|
randomId(prefix?, length?, random?) | Random id such as wr-input-a8f2bx1k9q4z, safe on the server. length is the random part, clamped to [4, 64]. random replaces the byte source, for a fixed id in tests. | (prefix = 'wr', length = 12, random?: (byteLength: number) => Uint8Array) => string | — |