Module

utils/difftochanges

@ckeditor/ckeditor5-utils/src/difftochanges

module

Filtering

Interfaces

Type Definitions

  • Change

Functions

  • diffToChanges( diff, output ) → Array<Change<T>>

    Creates 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.

    const 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( '' ); // -> true
    

    Type parameters

    T

    The 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.