MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / dockerPortsParse

Function dockerPortsParse

frontend/src/tools/common.ts:132–172  ·  view source on GitHub ↗
(ports: string[])

Source from the content-addressed store, hash-verified

130};
131
132export const dockerPortsParse = (ports: string[]) => {
133 let joinArr = ports.join(":");
134 let tempAddr: RegExpMatchArray | null;
135 const ipMaps = new Map();
136
137 if (isIPv6(joinArr)) {
138 tempAddr = joinArr.match(/\[([0-9a-fA-F:]+)\]/g);
139 for (let i = 0; i < tempAddr!.length; i++) {
140 joinArr = joinArr.replace(tempAddr![i], "IPv6_" + i);
141 ipMaps.set("IPv6_" + i, tempAddr![i]);
142 }
143 }
144
145 let p = isIPv6(ports.join(":")) ? joinArr.split(":") : ports;
146
147 let p1 = [],
148 p2 = [];
149
150 for (let i = 0; i < p.length; i++) {
151 if (
152 (isInt(p[0]) && p.length === 3 && i < 1) ||
153 (!isInt(p[0]) && p.length === 3 && i < 2) ||
154 (p.length === 4 && i < 2)
155 ) {
156 p1.push(p[i]);
157 } else if (p.length === 2) {
158 return { port1: p[0], port2: p[1] };
159 } else {
160 p2.push(p[i]);
161 }
162 }
163
164 const v4 = { port1: p1.join(":"), port2: p2.join(":") };
165
166 const v6 = {
167 port1: p1.length === 1 ? p1[0] : p1.join(":").replace(p1[0], ipMaps.get(p1[0])),
168 port2: p2.length === 1 ? p2[0] : p2.join(":").replace(p2[0], ipMaps.get(p2[0]))
169 };
170
171 return isIPv6(ports.join(":")) ? v6 : v4;
172};
173
174export const dockerPortsArray = (ports: string[]) => {
175 const portArray = ports.map((iterator) => {

Callers 1

dockerPortsArrayFunction · 0.85

Calls 5

isIPv6Function · 0.85
isIntFunction · 0.85
setMethod · 0.45
pushMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected