import { State , StateMachine } from 'xstate' ; import { Replacer } from './types' ; import { stringify } from './utils' ; export function selectivelyStringify < T extends object > ( value , keys , replacer ? ) { const selected = { } ; for ( const key of keys ) { selected [ key ] = value [ key ] ; } const serialized = JSON . parse ( stringify ( selected , replacer ) ) ; return stringify ( { ... value , ... serialized } ) ; } export function stringifyState ( state , replacer ? ) { return selectivelyStringify ( state , [ 'context' , 'event' , '_event' ] , replacer ) ; } export function stringifyMachine ( machine , replacer ? ) { return selectivelyStringify ( machine , [ 'context' ] , replacer ) ; }