Skip to content

Automatically merge two concurrently modified strings.

License

Notifications You must be signed in to change notification settings

johannesspohr/string-patch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-patch

This function can merge two strings that were edited concurrently. So for example, when a user is working in an input and changes are sent from the server, the inputs can be merged.

Installation

$ npm install string-patch

Usage

import smartMerge from 'string-patch';

var out = smartMerge("Hello, World", "Hello World", "Hello, Darkness"); // "Hello Darkness"

In this example, the algorithm merges the deleted comma with the change of the word "World" to "Darkness". The first parameter is the common base of both changes, the second is the result of the first change. The second parameter is the change that will overwrite the change made first in case of a conflict.

Pre-ES6

This is compiled using babel, so you have to explicitly reference the default export to get the smartMerge-Function.

var smartMerge = require('string-patch').default;

var out = smartMerge("Hello, World", "Hello World", "Hello, Darkness"); // "Hello Darkness"

License

MIT

About

Automatically merge two concurrently modified strings.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published