Utils.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export class Utils {
  2. /**
  3. * @type {string}
  4. */
  5. public static readonly baseMultipleSourcesIdentifiersPrefix: string = 'a';
  6. /**
  7. * @type {string}
  8. */
  9. public static readonly hexadecimalPrefix: string = '0x';
  10. /**
  11. * @param {string} version
  12. * @param {string} buildTimestamp
  13. * @returns {string}
  14. */
  15. public static buildVersionMessage (version?: string, buildTimestamp?: string): string {
  16. if (!version || !buildTimestamp) {
  17. return 'unknown';
  18. }
  19. const buildDate: string = new Date(parseInt(buildTimestamp, 10)).toISOString();
  20. return `${version}_${buildDate}`;
  21. }
  22. /**
  23. * @param {string} url
  24. * @returns {string}
  25. */
  26. public static extractDomainFrom (url: string): string {
  27. let domain: string;
  28. if (url.includes('://') || url.indexOf('//') === 0) {
  29. domain = url.split('/')[2];
  30. } else {
  31. domain = url.split('/')[0];
  32. }
  33. domain = domain.split(':')[0];
  34. return domain;
  35. }
  36. /**
  37. * @param {string | undefined} identifiersPrefix
  38. * @param {number} sourceCodeIndex
  39. * @returns {string}
  40. */
  41. public static getIdentifiersPrefixForMultipleSources (
  42. identifiersPrefix: string | undefined,
  43. sourceCodeIndex: number
  44. ): string {
  45. const baseIdentifiersPrefix: string = !!identifiersPrefix
  46. ? identifiersPrefix
  47. : Utils.baseMultipleSourcesIdentifiersPrefix;
  48. return `${baseIdentifiersPrefix}${sourceCodeIndex}`;
  49. }
  50. }