No function to apply diffs from `diffChars`, `diffWords`, etc.

Open
#95 2 comments 4 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
tooling

Research direction

Start by reading the existing createPatch and applyPatch APIs, then inspect how diffWords and related functions produce Change Objects. Define how a new application entry point should match and consume those objects without relying on line context. Done means the provided diffWords example transforms "hello world" into "hello my friend" and the existing patch behavior remains intact.

Written by the indexing model from the issue text.

Description

major-new-feature

While you can create a unified diff with createPatch and then apply that to another string using applyPatch, there doesn't seem to be a way to apply Change Objects.

I think this would be helpful to apply diffs to data where line-context is not sufficient to match the diff.

e.g., something like:

const str1 = 'Greetings,\nhello world'
const str2 = 'Greetings\nhello my friend'
const diffs = diffWords( str1, str2 )
const result = applyDiffs( 'hello world', diffs )
expect( result ).to.equal( 'hello my friend' )
Dominant language
JavaScript
Stars
9.2k
Forks
555
Avg merge
1d 9h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kpdecker/jsdiff

All issues in kpdecker/jsdiff

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.