
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Native bindings for libxdiff in Bare. Provides both asynchronous and synchronous APIs for diffing and merging text data.
npm install bare-xdiff
const { diff, merge, diffSync, mergeSync } = require('bare-xdiff')
const b4a = require('b4a')
// Async API
const patch = await diff(originalBuffer, modifiedBuffer)
const result = await merge(ancestorBuffer, oursBuffer, theirsBuffer)
// Sync API
const patch = diffSync(originalBuffer, modifiedBuffer)
const result = mergeSync(ancestorBuffer, oursBuffer, theirsBuffer)
diff(a, b[, options])
Generates a unified diff patch from two buffer inputs.
a
- Original data (Uint8Array)b
- Modified data (Uint8Array)options
- Optional diff optionsReturns a Promise<Uint8Array>
containing the diff patch.
ignoreWhitespace
- Ignore all whitespace differencesignoreWhitespaceChange
- Ignore changes in amount of whitespaceignoreWhitespaceAtEol
- Ignore whitespace at end of lineignoreBlankLines
- Ignore blank line changesalgorithm
- Diff algorithm: 'minimal'
, 'patience'
, or 'histogram'
merge(ancestor, ours, theirs[, options])
Performs a three-way merge of buffers.
ancestor
- Original/ancestor data (Uint8Array)ours
- Our changes data (Uint8Array)theirs
- Their changes data (Uint8Array)options
- Optional merge optionsReturns a Promise<{conflict: boolean, output: Uint8Array}>
containing conflict status and merged data.
level
- Merge level: 'minimal'
, 'eager'
, 'zealous'
, or 'zealous_alnum'
favor
- Conflict resolution: 'ours'
, 'theirs'
, or 'union'
style
- Output style: 'normal'
, 'diff3'
, or 'zealous_diff3'
markerSize
- Conflict marker size (default: 7)diffSync(a, b[, options])
Synchronous version of diff()
. Returns a Uint8Array
directly.
mergeSync(ancestor, ours, theirs[, options])
Synchronous version of merge()
. Returns a {conflict: boolean, output: Uint8Array}
directly.
const { diff } = require('bare-xdiff')
const b4a = require('b4a')
const a = b4a.from('hello world\n')
const b = b4a.from('hello bare\n')
const patch = await diff(a, b)
console.log(b4a.toString(patch))
// Output:
// @@ -1 +1 @@
// -hello world
// +hello bare
const { diff } = require('bare-xdiff')
const b4a = require('b4a')
const a = b4a.from('hello world\n')
const b = b4a.from('hello world\n') // extra space
const patch = await diff(a, b, { ignoreWhitespaceChange: true })
console.log(patch.length) // 0 - no differences found
const { diff } = require('bare-xdiff')
const b4a = require('b4a')
const a = b4a.from('line1\nline2\nline3\n')
const b = b4a.from('line1\nmodified\nline3\n')
const minimal = await diff(a, b, { algorithm: 'minimal' })
const patience = await diff(a, b, { algorithm: 'patience' })
const histogram = await diff(a, b, { algorithm: 'histogram' })
const { merge } = require('bare-xdiff')
const b4a = require('b4a')
const ancestor = b4a.from('original\nline\n')
const ours = b4a.from('our\nline\n')
const theirs = b4a.from('original\ntheir line\n')
const result = await merge(ancestor, ours, theirs)
console.log(b4a.toString(result.output))
console.log('Conflict detected:', result.conflict)
// Output includes merged content or conflict markers
const { merge } = require('bare-xdiff')
const b4a = require('b4a')
// Always favor our changes in conflicts
const result = await merge(ancestor, ours, theirs, { favor: 'ours' })
console.log('Conflict detected:', result.conflict)
// Use diff3 style conflict markers
const result = await merge(ancestor, ours, theirs, { style: 'diff3' })
console.log('Conflict detected:', result.conflict)
const { diffSync, mergeSync } = require('bare-xdiff')
const b4a = require('b4a')
// Blocking operations - no async/await needed
const patch = diffSync(bufferA, bufferB)
const result = mergeSync(ancestor, ours, theirs)
console.log('Conflict detected:', result.conflict)
Use the sync API for better performance on small to medium files. Use the async API for large files or when you need to avoid blocking the event loop.
Apache-2.0
FAQs
libxdiff bindings for Bare
We found that bare-xdiff demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.