8
0

uid.js 587 B

12345678910111213141516171819202122
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * Returns a unique id. This id is a number (starting from 1) which will never get repeated on successive calls
  7. * to this method.
  8. *
  9. * @function
  10. * @memberOf utils
  11. * @returns {String} A string representing the id.
  12. */
  13. export default () => {
  14. let uuid = 'e'; // Make sure that id does not start with number.
  15. for ( let i = 0; i < 8; i++ ) {
  16. uuid += Math.floor( ( 1 + Math.random() ) * 0x10000 ).toString( 16 ).substring( 1 );
  17. }
  18. return uuid;
  19. };