helpers.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.spanAllZeroes = spanAllZeroes;
  4. exports.spanAll = spanAll;
  5. exports.spanLeadingZeroes = spanLeadingZeroes;
  6. exports.simpleGroup = simpleGroup;
  7. /**
  8. * @returns {String} the string with all zeroes contained in a <span>
  9. */
  10. function spanAllZeroes(s) {
  11. return s.replace(/(0+)/g, '<span class="zero">$1</span>');
  12. }
  13. /**
  14. * @returns {String} the string with each character contained in a <span>
  15. */
  16. function spanAll(s, offset = 0) {
  17. const letters = s.split('');
  18. return letters
  19. .map((n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`)
  20. .join('');
  21. }
  22. function spanLeadingZeroesSimple(group) {
  23. return group.replace(/^(0+)/, '<span class="zero">$1</span>');
  24. }
  25. /**
  26. * @returns {String} the string with leading zeroes contained in a <span>
  27. */
  28. function spanLeadingZeroes(address) {
  29. const groups = address.split(':');
  30. return groups.map((g) => spanLeadingZeroesSimple(g)).join(':');
  31. }
  32. /**
  33. * Groups an address
  34. * @returns {String} a grouped address
  35. */
  36. function simpleGroup(addressString, offset = 0) {
  37. const groups = addressString.split(':');
  38. return groups.map((g, i) => {
  39. if (/group-v4/.test(g)) {
  40. return g;
  41. }
  42. return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`;
  43. });
  44. }
  45. //# sourceMappingURL=helpers.js.map