import { ObjectId } from "../objectid/ObjectId" ; import { isObject , keysOf , isInfOrNaN } from "../utilities" ; import { toJSONValueHelper } from "./toJSONValueHelper" ; export const adjustTypesToJSONValue = ( obj ) => { if ( obj === null ) { return null ; } const maybeChanged = toJSONValueHelper ( obj ) ; if ( maybeChanged !== undefined ) { return maybeChanged ; } if ( ! isObject ( obj ) ) { return obj ; } keysOf ( obj ) . forEach ( ( key ) => { const value = obj [ key ] ; if ( ! isObject ( value ) && value !== undefined && ! isInfOrNaN ( value ) && ! ( value instanceof ObjectId ) ) { return ; } const changed = toJSONValueHelper ( value ) ; if ( changed ) { obj [ key ] = changed ; return ; } adjustTypesToJSONValue ( value ) ; } ) ; return obj ; } ;