returns export function replace ( content , { replaceContent , replacePattern } ) { const replacePatternOccurrence = content . search ( replacePattern ) ; if ( replacePatternOccurrence !== - 1 ) { return [ true , content . replace ( replacePattern , replaceContent ) ] ; } return [ false , content ] ; } returns export function insert ( content , { insertContent , insertPattern } , insertBeforeLastOccurrence = false ) { if ( insertBeforeLastOccurrence ) { return insertBeforeLastOccurrenceFun ( content , { insertContent , insertPattern } ) ; } const insertPatternOccurrence = content . search ( insertPattern ) ; if ( insertPatternOccurrence !== - 1 ) { return [ true , `${ content . slice ( 0 , insertPatternOccurrence ) }${ insertContent }${ content . slice ( insertPatternOccurrence ) }` , ] ; } return [ false , content ] ; } returns function insertBeforeLastOccurrenceFun ( content , { insertContent , insertPattern } ) { const results = [ ... content . matchAll ( new RegExp ( insertPattern , 'gm' ) ) ] ; const patternLastOccurrence = results [ results . length - 1 ] ; if ( ! patternLastOccurrence ) { return [ false , content ] ; } return [ true , `${ content . slice ( 0 , patternLastOccurrence . index ) }${ insertContent }${ content . slice ( patternLastOccurrence . index ) }` , ] ; }