UNPKG

e2ed

Version:

E2E testing framework over Playwright

31 lines (30 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseValueAsJsonIfNeeded = void 0; const parseMaybeEmptyValueAsJson_1 = require("./parseMaybeEmptyValueAsJson"); /** * Parses `unknown` value as JSON, if needed. * If `isValueInJsonFormat` is `true`, then parses value as JSON and saves parse error. * If `isValueInJsonFormat` is `false`, then returns value as is. * If `isValueInJsonFormat` is `undefined`, then safely tries to parse value as JSON. */ const parseValueAsJsonIfNeeded = (originalValue, isValueInJsonFormat) => { let hasParseError = false; let value = originalValue; if (isValueInJsonFormat === true) { try { value = (0, parseMaybeEmptyValueAsJson_1.parseMaybeEmptyValueAsJson)(originalValue); } catch { hasParseError = true; } } else if (isValueInJsonFormat !== false) { try { value = (0, parseMaybeEmptyValueAsJson_1.parseMaybeEmptyValueAsJson)(originalValue); } catch { } } return { hasParseError, value }; }; exports.parseValueAsJsonIfNeeded = parseValueAsJsonIfNeeded;