All files / src/components/DeveloperApi utils.ts

30.76% Statements 4/13
18.18% Branches 2/11
100% Functions 1/1
30.76% Lines 4/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  3x   3x                   3x                   3x  
export function validIpAddress(ip:string) {
    const parts = ip.split(/[.:]/);
  
    Iif (parts.length === 4) {
  
        // Check IPv4 parts
        for (const part of parts) {
            const num = parseInt(part);
            if (isNaN(num) || num < 0 || num > 255) {
                return false;
            }
        }
        return true;
    } else Iif (parts.length === 8) {
  
        // Check IPv6 parts
        for (const part of parts) {
            if (!/^[0-9a-fA-F]{1,4}$/.test(part)) {
                return false;
            }
        }
        return true;
    }
    return false;
  }