UtilUpdated in v16Optional

wrRandomId

Short prefixed random id, for <label for> and aria-describedby pairs.

Usage

import { wrRandomId } from 'ngwr/utils';

const id = wrRandomId('wr-input');       // 'wr-input-a8f2bx1k9q4z'
const short = wrRandomId('wr-input', 6); // 'wr-input-h7m4k2'

API

NameDescriptionTypeDefault
wrRandomId(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—

See also