@grafana/faro-core
Version:
Core package of Faro.
29 lines • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCircularDependencyReplacer = getCircularDependencyReplacer;
exports.stringifyExternalJson = stringifyExternalJson;
exports.stringifyObjectValues = stringifyObjectValues;
const is_1 = require("./is");
function getCircularDependencyReplacer() {
const valueSeen = new WeakSet();
return function (_key, value) {
if ((0, is_1.isObject)(value) && value !== null) {
if (valueSeen.has(value)) {
return null;
}
valueSeen.add(value);
}
return value;
};
}
function stringifyExternalJson(json = {}) {
return JSON.stringify(json !== null && json !== void 0 ? json : {}, getCircularDependencyReplacer());
}
function stringifyObjectValues(obj = {}) {
const o = {};
for (const [key, value] of Object.entries(obj)) {
o[key] = (0, is_1.isObject)(value) && value !== null ? stringifyExternalJson(value) : String(value);
}
return o;
}
//# sourceMappingURL=json.js.map