communication-react-19
Version:
React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)
35 lines • 993 B
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* Wrap JSON.stringify in a try-catch as JSON.stringify throws an exception if it fails.
*
* Use this only in areas where the JSON.stringify is non-critical and OK for the JSON.stringify to fail, such as logging.
*
* @internal
*/
export const _safeJSONStringify = (value, replacer = createSafeReplacer(), space) => {
try {
return JSON.stringify(value, replacer, space);
}
catch (e) {
console.error(e);
return undefined;
}
};
// Log all visited refs to avoid circular ref
const createSafeReplacer = () => {
const visited = new Set();
return function replacer(key, value) {
if (typeof value !== 'object') {
return value;
}
if (visited.has(value)) {
return 'Visited-Ref';
}
else {
visited.add(value);
return value;
}
};
};
//# sourceMappingURL=safeStringify.js.map