Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-conflict-json

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-conflict-json

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

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5M
increased by3.41%
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 14 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc