# All files / src/utils environmentUtils.ts

0% Statements 0/11
0% Branches 0/10
0% Functions 0/2
0% Lines 0/11

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
    26
    27

     /** Minimum valid network port. */
    export const MIN_PORT: number = 1;
    /** Maximum valid network port. */
    export const MAX_PORT: number = 65535;

    /** Returns true if portStr is empty (optional) or a valid integer in [1, 65535]. */
    export function isPortValid(portStr: string): boolean {
      if (!portStr.trim()) {
        return true;
      }
      const n = Number(portStr);
      return Number.isInteger(n) && n >= MIN_PORT && n <= MAX_PORT;
    }

    /** Parse adapter config JSON string into a record, defaulting to empty object. */
    export function parseAdapterConfig(raw: string): Record<string, unknown> {
      try {
        const parsed: unknown = JSON.parse(raw);
        if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
          return parsed as Record<string, unknown>;
        }
      } catch {
        // fall through
      }
      return {};
    }