UNPKG

@gravityforms/utils

Version:
22 lines (21 loc) 523 B
/** * @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 ) }`; }