parse-conflict-json
Parse a JSON string that has git merge conflicts, resolving if possible
Last updated 2 years ago by gar .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install parse-conflict-json 
SYNC missed versions from official npm registry.

parse-conflict-json

Parse a JSON string that has git merge conflicts, resolving if possible.

If the JSON is valid, it just does JSON.parse as normal.

If either side of the conflict is invalid JSON, then an error is thrown for that.

USAGE

// after a git merge that left some conflicts there
const data = fs.readFileSync('package-lock.json', 'utf8')

// reviverFunction is passed to JSON.parse as the reviver function
// preference defaults to 'ours', set to 'theirs' to prefer the other
// side's changes.
const parsed = parseConflictJson(data, reviverFunction, preference)

// returns true if the data looks like a conflicted diff file
parsed.isDiff(data)

Algorithm

If prefer is set to theirs, then the vaules of theirs and ours are switched in the resolver function. (Ie, we'll apply their changes on top of our object, rather than the other way around.)

  • Parse the conflicted file into 3 pieces: ours, theirs, and parent

  • Get the diff from parent to ours.

  • Apply each change of that diff to theirs.

    If any change in the diff set cannot be applied (ie, because they changed an object into a non-object and we changed a field on that object), then replace the object at the specified path with the object at the path in ours.

Current Tags

  • 3.0.1                                ...           latest (2 years ago)

9 Versions

  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (3)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |