helpers.js 1.6 KB

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