XYOracleNetwork/sdk-xyo-client-js

View on GitHub
packages/shared/src/dump.ts

Summary

Maintainability
A
0 mins
Test Coverage
export const dump = (object: unknown): string => {
  const cache: unknown[] = []
  return JSON.stringify(
    object,
    (key, value) => {
      if (typeof value === 'object' && value !== null) {
        // Duplicate reference found, discard key
        if (cache.includes(value)) {
          return '[circular]'
        }

        // Store value in our collection
        cache.push(value)
      }
      return value
    },
    2,
  )
}