1. 1 : /**
  2. 2 : * @file guid.js
  3. 3 : * @module guid
  4. 4 : */
  5. 5 :
  6. 6 : // Default value for GUIDs. This allows us to reset the GUID counter in tests.
  7. 7 : //
  8. 8 : // The initial GUID is 3 because some users have come to rely on the first
  9. 9 : // default player ID ending up as `vjs_video_3`.
  10. 10 : //
  11. 11 : // See: https://github.com/videojs/video.js/pull/6216
  12. 12 : const _initialGuid = 3;
  13. 13 :
  14. 14 : /**
  15. 15 : * Unique ID for an element or function
  16. 16 : *
  17. 17 : * @type {Number}
  18. 18 : */
  19. 19 : let _guid = _initialGuid;
  20. 20 :
  21. 21 : /**
  22. 22 : * Get a unique auto-incrementing ID by number that has not been returned before.
  23. 23 : *
  24. 24 : * @return {number}
  25. 25 : * A new unique ID.
  26. 26 : */
  27. 27 : export function newGUID() {
  28. 28 : return _guid++;
  29. 29 : }
  30. 30 :
  31. 31 : /**
  32. 32 : * Reset the unique auto-incrementing ID for testing only.
  33. 33 : */
  34. 34 : export function resetGuidInTestsOnly() {
  35. 35 : _guid = _initialGuid;
  36. 36 : }