All files / src/utils environmentUtils.ts

54.54% Statements 6/11
50% Branches 4/8
50% Functions 1/2
54.54% Lines 6/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  13x   13x       388x 292x   96x 96x                              
/** 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);
    Iif (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
      return parsed as Record<string, unknown>;
    }
  } catch {
    // fall through
  }
  return {};
}