source: node_modules/ip-address/src/v6/helpers.ts@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @returns {String} the string with all zeroes contained in a <span>
3 */
4export function spanAllZeroes(s: string): string {
5 return s.replace(/(0+)/g, '<span class="zero">$1</span>');
6}
7
8/**
9 * @returns {String} the string with each character contained in a <span>
10 */
11export function spanAll(s: string, offset: number = 0): string {
12 const letters = s.split('');
13
14 return letters
15 .map(
16 (n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`,
17 )
18 .join('');
19}
20
21function spanLeadingZeroesSimple(group: string): string {
22 return group.replace(/^(0+)/, '<span class="zero">$1</span>');
23}
24
25/**
26 * @returns {String} the string with leading zeroes contained in a <span>
27 */
28export function spanLeadingZeroes(address: string): string {
29 const groups = address.split(':');
30
31 return groups.map((g) => spanLeadingZeroesSimple(g)).join(':');
32}
33
34/**
35 * Groups an address
36 * @returns {String} a grouped address
37 */
38export function simpleGroup(addressString: string, offset: number = 0): string[] {
39 const groups = addressString.split(':');
40
41 return groups.map((g, i) => {
42 if (/group-v4/.test(g)) {
43 return g;
44 }
45
46 return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`;
47 });
48}
Note: See TracBrowser for help on using the repository browser.