INNER CODE UNIT · TypeScript

safeStringify

mowispace/react-native-logs · src/index.ts:71

const safeStringify = (value: unknown): string => {
  if (typeof value === "string") return value;
  if (typeof value === "function")
    return `[function ${value.name || "anonymous"}()]`;
  if (value instanceof Error) return value.stack || value.message;

  const cache = new Set();
  try {
    return JSON.stringify(
      value,
      (key, val) => {
        if (typeof val === "object" && val !== null) {
          if (cache.has(val)) {
            return "[Circular Reference]";
          }
          cache.add(val);
        }
        return val;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…