Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/suggest/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Skip categories where things look fine. Don't invent problems.

**Linting** — `.oxlintrc.json` rules that are stale, redundant, or missing for the code in `scripts/`, `src/`, and `test/`

**Packaging** — `package.json` `exports` conditions, `files`, and `types` that don't match what the build in `dist/` actually produces (ESM, CJS, IIFE, declarations)
**Packaging** — `package.json` `exports` conditions, `files`, and `types` that don't match what the build in `dist/` actually produces (ESM, IIFE, declarations)

**Developer Experience** — missing or misleading `package.json` scripts, incomplete `.gitignore`/`.gitattributes`, missing docs or source comments

Expand Down
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@ To install node-diff3 as a dependency in your project:
$ npm install --save node-diff3
```

**node-diff3** is distributed in CJS and ESM module formats for maxmimum compatibility. ([Read more about Javascript module formats](https://dev.to/iggredible/what-the-heck-are-cjs-amd-umd-and-esm-ikm))

**node-diff3** is written in TypeScript and distributed as an ESM module, with type declarations included. ([Read more about Javascript module formats](https://dev.to/iggredible/what-the-heck-are-cjs-amd-umd-and-esm-ikm))

```js
const Diff3 = require('node-diff3'); // CommonJS import all
const diff3Merge = require('node-diff3').diff3Merge; // CommonJS import named
// or
import * as Diff3 from 'node-diff3'; // ESM import all
import { diff3Merge } from 'node-diff3'; // ESM import named
```

CommonJS code can still `require('node-diff3')` on Node 20.19+ or 22.12+, which can load ESM modules with `require()`.

### Use in Browsers

You can also use **node-diff3** directly in a web browser. A good way to do this is to fetch the ["iife"](https://esbuild.github.io/api/#format-iife) bundle from the [jsDelivr CDN](https://www.jsdelivr.com/), which can even deliver minified versions.

When you load this file in a `<script>` tag, you'll get a `Diff3` global to use elsewhere in your scripts:
```html
<head>
<script src="https://cdn.jsdelivr.net/npm/node-diff3@latest/dist/diff3.iife.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/node-diff3@latest/dist/js/diff3.iife.min.js"></script>
</head>
…
<script>
Expand Down Expand Up @@ -93,7 +91,7 @@ Performs a 3-way diff on buffers `o` (original), and `a` and `b` (changed).
The buffers may be arrays or strings. If strings, they will be split into arrays on whitespace `/\s+/` by default.
The returned result alternates between "ok" and "conflict" blocks.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3Merge.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3Merge.test.ts

```js
const o = ['AA', 'ZZ', '00', 'M', '99'];
Expand All @@ -119,7 +117,7 @@ Options may passed as an object:

Passes arguments to [diff3Merge](#diff3Merge) to generate a diff3-style merge result.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/merge.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/merge.test.ts

```js
const r = Diff3.merge(a, o, b);
Expand Down Expand Up @@ -157,7 +155,7 @@ const result = r.result;

Passes arguments to [diff3Merge](#diff3Merge) to generate a diff3-style merge result with original (similar to [git-diff3](https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging)).

See examples: https://github.com/bhousel/node-diff3/blob/main/test/mergeDiff3.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/mergeDiff3.test.ts

```js
const r = Diff3.mergeDiff3(a, o, b, { label: { a: 'a', o: 'o', b: 'b' } });
Expand Down Expand Up @@ -210,15 +208,15 @@ Extra options:

Passes arguments to [diff3Merge](#diff3Merge) to generate a digin-style merge result.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/mergeDigIn.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/mergeDigIn.test.ts

&nbsp;

<a name="diff3MergeRegions" href="#diff3MergeRegions">#</a> <i>Diff3</i>.<b>diff3MergeRegions</b>(<i>a</i>, <i>o</i>, <i>b</i>)

Low-level function used by [diff3Merge](#diff3Merge) to determine the stable and unstable regions between `a`, `o`, `b`.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3MergeRegions.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3MergeRegions.test.ts


&nbsp;
Expand All @@ -232,7 +230,7 @@ See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3MergeReg
Performs a diff between arrays `buffer1` and `buffer2`.
The returned `patch` result contains the information about the differing regions and can be applied to `buffer1` to yield `buffer2`.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.ts

```js
const buffer1 = ['AA', 'a', 'b', 'c', 'ZZ', 'new', '00', 'a', 'a', 'M', '99'];
Expand All @@ -247,7 +245,7 @@ const patch = Diff3.diffPatch(buffer1, buffer2);

Applies a patch to a buffer, returning a new buffer without modifying the original.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.ts

```js
const result = Diff3.patch(buffer1, patch);
Expand All @@ -261,7 +259,7 @@ const result = Diff3.patch(buffer1, patch);
Strips some extra information from the patch, returning a new patch without modifying the original.
The "stripped" patch can still patch `buffer1` -> `buffer2`, but can no longer be inverted.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.ts

```js
const stripped = Diff3.stripPatch(patch);
Expand All @@ -274,7 +272,7 @@ const stripped = Diff3.stripPatch(patch);

Inverts the patch (for example to turn `buffer2` back into `buffer1`), returning a new patch without modifying the original.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.ts

```js
const inverted = Diff3.invertPatch(patch);
Expand All @@ -287,15 +285,15 @@ const inverted = Diff3.invertPatch(patch);

Returns a comm-style result of the differences between `buffer1` and `buffer2`.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffComm.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffComm.test.ts

&nbsp;

<a name="diffIndices" href="#diffIndices">#</a> <i>Diff3</i>.<b>diffIndices</b>(<i>buffer1</i>, <i>buffer2</i>)

Low-level function used by [diff3MergeRegions](#diff3MergeRegions) to determine differing regions between `buffer1` and `buffer2`.

See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffIndices.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffIndices.test.ts


&nbsp;
Expand All @@ -313,7 +311,7 @@ See also:
* http://www.cs.dartmouth.edu/~doug/
* https://en.wikipedia.org/wiki/Longest_common_subsequence_problem

See examples: https://github.com/bhousel/node-diff3/blob/main/test/LCS.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/LCS.test.ts


&nbsp;
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@
],
"type": "module",
"exports": {
"bun": "./src/diff3.mjs",
"types": "./src/diff3.d.ts",
"import": "./dist/diff3.mjs",
"require": "./dist/diff3.cjs",
"browser": "./dist/diff3.iife.js"
"types": "./dist/ts/diff3.d.ts",
"bun": "./src/diff3.ts",
"import": "./dist/js/diff3.mjs",
"require": "./dist/js/diff3.mjs",
"browser": "./dist/js/diff3.iife.js",
"default": "./dist/js/diff3.mjs"
},
"scripts": {
"all": "bun run --sequential clean check build test",
"clean": "bun ./scripts/clean.ts",
"build": "bun run --parallel 'build:*'",
"build:js": "bun ./scripts/build_js.ts",
"build:ts": "tsc",
"build:ts": "tsc -p tsconfig.build.json",
"check": "bun run --parallel 'check:*'",
"check:lint": "oxlint ./scripts ./src ./test",
"check:types": "tsc --noEmit",
"test": "bun test --dots --coverage ./test"
},
"devDependencies": {
Expand Down
15 changes: 3 additions & 12 deletions scripts/build_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
await Promise.all([
Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
outdir: './dist/js',
target: 'browser',
format: 'iife',
sourcemap: 'linked',
naming: 'diff3.iife.[ext]' // .iife.js
}),

Bun.build({
entrypoints: ['./src/diff3.mjs'],
outdir: './dist',
target: 'node',
format: 'cjs',
sourcemap: 'linked',
naming: 'diff3.c[ext]' // .cjs
}),

Bun.build({
entrypoints: ['./src/diff3.mjs'],
outdir: './dist',
entrypoints: ['./src/diff3.ts'],
outdir: './dist/js',
target: 'node',
format: 'esm',
sourcemap: 'linked',
Expand Down
188 changes: 0 additions & 188 deletions src/diff3.d.ts

This file was deleted.

Loading
Loading