import 'weakset' ; const cyclicalReferenceReplacer = ( ) => { const seen = new WeakSet ( ) ; return ( _ , value ) => { if ( typeof value === 'object' && value !== null ) { if ( seen . has ( value ) ) { return '[Cyclical Reference]' ; } seen . add ( value ) ; } return value ; } ; } ; export const stringify = ( value ) : string => JSON . stringify ( value , cyclicalReferenceReplacer ( ) ) ;