UNPKG

@jsdevtools/karma-host-environment

Version:

Access host info (OS, browser version, environment variables) in browser tests

41 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hostToPOJO = void 0; const host_environment_1 = require("@jsdevtools/host-environment"); /** * Returns a copy of the `host` object as a POJO (plain old JavaScript object) * that's safe to serialize as JSON. */ function hostToPOJO() { let pojo = host_environment_1.default.toJSON(); pojo.global = sanitize(global, 2); return pojo; } exports.hostToPOJO = hostToPOJO; /** * Returns a sanitized value that is safe to serialize as JSON. */ function sanitize(value, depth) { if (typeof value !== "object" || value === null) { return value; } if (Array.isArray(value)) { if (depth) { return value.map((item) => sanitize(item, depth - 1)); } else { return []; } } if (depth) { let clone = {}; for (let key of Object.keys(value)) { clone[key] = sanitize(value[key], depth - 1); } return clone; } else { return {}; } } //# sourceMappingURL=host-to-pojo.js.map