src/unwrapObject.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import mapObject from "./mapObject"
import { isPII } from "./pii"
import unwrap from "./unwrap"

const unwrapObject = (input: unknown, maxDepth = Infinity): unknown => {
  if (maxDepth === 0) {
    return null
  }

  return mapObject(
    (v: unknown) => unwrapObject(v, maxDepth - 1),
    isPII(input) ? unwrap(input) : input,
  )
}

export default unwrapObject