utils/difftochanges
module
Interfaces
module:utils/difftochanges~DeleteChangemodule:utils/difftochanges~InsertChange
Type Definitions
module:utils/difftochanges~Change
Functions
diffToChanges( diff, output ) → Array<Change<T>>module:utils/difftochanges~diffToChangesCreates a set of changes which need to be applied to the input in order to transform it into the output. This function can be used with strings or arrays.
Copy codeconst input = Array.from( 'abc' ); const output = Array.from( 'xaby' ); const changes = diffToChanges( diff( input, output ), output ); changes.forEach( change => { if ( change.type == 'insert' ) { input.splice( change.index, 0, ...change.values ); } else if ( change.type == 'delete' ) { input.splice( change.index, change.howMany ); } } ); input.join( '' ) == output.join( '' ); // -> trueType parameters
TThe type of output array element.
Parameters
diff: readonly Array<DiffResult>Result of
diff.output: ArrayLike<T>The string or array which was passed as diff's output.
Returns
Array<Change<T>>Set of changes (insert or delete) which need to be applied to the input in order to transform it into the output.