8
0

uid.js 593 B

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