data_unique-id.js

/**
 * @module uniqueId
 * @description Generates a unique id.
 *
 * @since 1.0.0
 *
 * @param {string} prefix Prefix to added to the generated unique id.
 *
 * @return {string} Returns a unique Id, prepended with the speficied prefix.
 *
 * @example
 * import { uniqueId } from "@gravityforms/utils";
 *
 * function Example() {
 *   const id = uniqueId( 'gform' );
 * }
 *
 */
export default function( prefix = 'id' ) {
	return `${ prefix.length ? `${ prefix }-` : '' }${ Math.random().toString( 36 ).substr( 2, 9 ) }`;
}