es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
26 lines • 858 B
text/typescript
//#region src/compat/util/uniqueId.d.ts
/**
* Generates a unique identifier, optionally prefixed with a given string.
*
* @param [prefix] - An optional string to prefix the unique identifier.
* If not provided or not a string, only the unique
* numeric identifier is returned.
* @returns A string containing the unique identifier, with the optional
* prefix if provided.
*
* @example
* // Generate a unique ID with a prefix
* uniqueId('user_'); // => 'user_1'
*
* @example
* // Generate a unique ID without a prefix
* uniqueId(); // => '2'
*
* @example
* // Subsequent calls increment the internal counter
* uniqueId('item_'); // => 'item_3'
* uniqueId(); // => '4'
*/
declare function uniqueId(prefix?: string): string;
//#endregion
export { uniqueId };