Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

id-generator.js 959B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @fileoverview A class of identifiers generator for code path segments.
  3. *
  4. * Each rule uses the identifier of code path segments to store additional
  5. * information of the code path.
  6. *
  7. * @author Toru Nagashima
  8. */
  9. "use strict";
  10. //------------------------------------------------------------------------------
  11. // Public Interface
  12. //------------------------------------------------------------------------------
  13. /**
  14. * A generator for unique ids.
  15. */
  16. class IdGenerator {
  17. /**
  18. * @param {string} prefix - Optional. A prefix of generated ids.
  19. */
  20. constructor(prefix) {
  21. this.prefix = String(prefix);
  22. this.n = 0;
  23. }
  24. /**
  25. * Generates id.
  26. *
  27. * @returns {string} A generated id.
  28. */
  29. next() {
  30. this.n = 1 + this.n | 0;
  31. /* istanbul ignore if */
  32. if (this.n < 0) {
  33. this.n = 1;
  34. }
  35. return this.prefix + this.n;
  36. }
  37. }
  38. module.exports = IdGenerator;