File size: 1,284 Bytes
f107c64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * @returns {String} the string with all zeroes contained in a <span>
 */
export function spanAllZeroes(s: string): string {
  return s.replace(/(0+)/g, '<span class="zero">$1</span>');
}

/**
 * @returns {String} the string with each character contained in a <span>
 */
export function spanAll(s: string, offset: number = 0): string {
  const letters = s.split('');

  return letters
    .map(
      (n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`,
    )
    .join('');
}

function spanLeadingZeroesSimple(group: string): string {
  return group.replace(/^(0+)/, '<span class="zero">$1</span>');
}

/**
 * @returns {String} the string with leading zeroes contained in a <span>
 */
export function spanLeadingZeroes(address: string): string {
  const groups = address.split(':');

  return groups.map((g) => spanLeadingZeroesSimple(g)).join(':');
}

/**
 * Groups an address
 * @returns {String} a grouped address
 */
export function simpleGroup(addressString: string, offset: number = 0): string[] {
  const groups = addressString.split(':');

  return groups.map((g, i) => {
    if (/group-v4/.test(g)) {
      return g;
    }

    return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`;
  });
}