uid.js 720 B

123456789101112131415161718192021222324
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module utils/uid
  7. */
  8. /**
  9. * Returns a unique id. This id consist of an 'e' character and a randomly generated string of 32 aphanumeric characters.
  10. * Each character in uid string represents a hexadecimal digit (base 16).
  11. *
  12. * @returns {String} A hexadecimal 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. }