diff --git a/packages/auth/src/core/util/event_id.ts b/packages/auth/src/core/util/event_id.ts index 6e2e02fca63..39ef2813e3e 100644 --- a/packages/auth/src/core/util/event_id.ts +++ b/packages/auth/src/core/util/event_id.ts @@ -15,6 +15,25 @@ * limitations under the License. */ +/** + * Generates a unique event identifier with a customizable prefix and length. + * + * This function creates a random alphanumeric string by repeatedly generating + * random numbers and concatenating their string representations. The resulting + * event ID consists of the provided prefix followed by a randomly generated + * string of the specified number of digits. + * + * @param prefix - The string to prepend to the generated random number sequence. Defaults to an empty string. + * @param digits - The number of random digits to generate for the event ID. Defaults to 10. + * @returns A string containing the prefix followed by the randomly generated digits. + * + * @example + * ```typescript + * _generateEventId('evt_', 8); // Returns something like: 'evt_12345678' + * _generateEventId(); // Returns something like: '1234567890' + * ``` + */ + export function _generateEventId(prefix = '', digits = 10): string { let random = ''; for (let i = 0; i < digits; i++) {