User:Daniel Quinlan/Scripts/RangeHelper.js: Difference between revisions

Content deleted Content added
reorder some functions, other minor changes
simplified IPv6 compression function
Line 111:
 
static #compressIPv6(ipv6) {
let run = null;
for (const zeroBlocksmatch =of ipv6.matchmatchAll(/:?\b0b(0(?:\:0)+)\b:?/g);) {
if (!zeroBlocks) return ipv6;
if (!run || match[1].length > run[1].length) {
const longestZeroBlock = zeroBlocks.reduce((longest, current) => {
run = match;
return current.length > longest.length ? current : longest;
}, "");
if (longestZeroBlock) {
return ipv6.replace(new RegExp(`:?\\b${longestZeroBlock}\\b:?`), '::');
}
return run ? `${ipv6.slice(0, run.index)}::${ipv6.slice(run.index + run[0].length)}` : ipv6;
return ipv6;
}
}