internal export function toAngularJSON ( obj , pretty ? ) { if ( obj === undefined ) return '' ; if ( typeof pretty === 'number' ) { pretty = pretty ? 2 : null ; } return JSON . stringify ( obj , toJsonReplacer , pretty ) ; } function isWindow ( obj ) { return obj && obj . window === obj ; } function isScope ( obj ) { return obj && obj . $evalAsync && obj . $watch ; } function toJsonReplacer ( key , value ) { let val = value ; if ( typeof key === 'string' && key . charAt ( 0 ) === '$' && key . charAt ( 1 ) === '$' ) { val = undefined ; } else if ( isWindow ( value ) ) { val = '$WINDOW' ; } else if ( value && window . document === value ) { val = '$DOCUMENT' ; } else if ( isScope ( value ) ) { val = '$SCOPE' ; } return val ; }