{"_id":"@ap-ent/diff","name":"@ap-ent/diff","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ap-ent/diff","version":"1.0.0","description":"Zero-dependency TypeScript diff and patch engine","license":"MIT","author":{"name":"Gordon Schauer"},"type":"module","main":"./dist/cjs/index.cjs","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","exports":{".":{"types":"./dist/esm/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.cjs"}},"scripts":{"build":"tsup","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","lint":"eslint src __tests__","typecheck":"tsc --noEmit"},"devDependencies":{"@types/node":"^20.0.0","eslint":"^8.0.0","@typescript-eslint/parser":"^7.0.0","@typescript-eslint/eslint-plugin":"^7.0.0","tsup":"^8.0.0","typescript":"^5.4.0","vitest":"^1.6.0"},"keywords":["diff","patch","json-diff","typescript","zero-dependency"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/AloysiusProductions/ap-diff.git"},"homepage":"https://github.com/AloysiusProductions/ap-diff#readme","bugs":{"url":"https://github.com/AloysiusProductions/ap-diff/issues"},"gitHead":"9a923aa6e1f91881a352ebbfba2de0976b393176","_id":"@ap-ent/diff@1.0.0","_nodeVersion":"25.8.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-eM6nCRQLk8AgtYTDHdnUzGkB8SNLf2h50BQo5XF/Ey1gpCDSEyAt12KP6I15UA8vqlFi0vVYNVVj4hb/Qvmr8Q==","shasum":"adf7b4fb32fe943f6e5e9f29191bd3013caef520","tarball":"https://registry.npmjs.org/@ap-ent/diff/-/diff-1.0.0.tgz","fileCount":10,"unpackedSize":34940,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCdrEVKG7p3k3/CYgx0IciBLvkRyGgoZLjebvWF7xCegQIgZ7ZEAyOayi05LRawNk1Fk6+4LA00D5KJmeoyV108sDo="}]},"_npmUser":{"name":"irishrocker1125","email":"irishrocker1125@gmail.com"},"directories":{},"maintainers":[{"name":"irishrocker1125","email":"irishrocker1125@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/diff_1.0.0_1775331595020_0.9748213947025295"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-04T19:39:54.892Z","1.0.0":"2026-04-04T19:39:55.169Z","modified":"2026-04-04T19:39:55.367Z"},"maintainers":[{"name":"irishrocker1125","email":"irishrocker1125@gmail.com"}],"description":"Zero-dependency TypeScript diff and patch engine","homepage":"https://github.com/AloysiusProductions/ap-diff#readme","keywords":["diff","patch","json-diff","typescript","zero-dependency"],"repository":{"type":"git","url":"git+https://github.com/AloysiusProductions/ap-diff.git"},"author":{"name":"Gordon Schauer"},"bugs":{"url":"https://github.com/AloysiusProductions/ap-diff/issues"},"license":"MIT","readme":"# @ap/diff\r\n\r\nZero-dependency TypeScript diff and patch engine. Supports line-level and character-level text diffing, deep JSON structural diffs, patch generation, patch application, and conflict detection.\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @ap/diff\r\n```\r\n\r\n## Usage\r\n\r\n### Text / Line Diffing\r\n\r\n```typescript\r\nimport { diffLines, diffText, renderTextDiff } from '@ap/diff';\r\n\r\nconst lines = diffLines('Hello World', 'Hello AP');\r\n// [{ type: 'remove', line: 'Hello World' }, { type: 'add', line: 'Hello AP' }]\r\n\r\nconst chars = diffText('abc', 'axc');\r\nconst rendered = renderTextDiff(chars);\r\n// [{ type: 'equal', text: 'a' }, { type: 'remove', text: 'b' }, { type: 'add', text: 'x' }, { type: 'equal', text: 'c' }]\r\n```\r\n\r\n### JSON Diffing\r\n\r\n```typescript\r\nimport { diffJson, applyPatch, summarizePatch } from '@ap/diff';\r\n\r\nconst a = { name: 'Alice', age: 30 };\r\nconst b = { name: 'Alice', age: 31, city: 'NYC' };\r\n\r\nconst patch = diffJson(a, b);\r\n// { operations: [{ op: 'replace', path: ['age'], oldValue: 30, value: 31 }, { op: 'add', path: ['city'], value: 'NYC' }] }\r\n\r\nconst result = applyPatch(a, patch);\r\n// { name: 'Alice', age: 31, city: 'NYC' }  — original `a` is unchanged\r\n\r\nconsole.log(summarizePatch(patch));\r\n// \"1 added, 1 modified\"\r\n```\r\n\r\n### Safe Patch Application\r\n\r\n```typescript\r\nimport { applyPatchSafe } from '@ap/diff';\r\n\r\nconst result = applyPatchSafe(modifiedOriginal, patch);\r\nif (result.ok) {\r\n  console.log(result.result);\r\n} else {\r\n  console.log(result.conflicts);\r\n  // [{ path: ['age'], reason: 'expected 30 but found 35' }]\r\n}\r\n```\r\n\r\n## API\r\n\r\n| Function | Description |\r\n|---|---|\r\n| `diffText(a, b)` | Character-level diff |\r\n| `diffLines(a, b)` | Line-level diff |\r\n| `diffJson(a, b)` | Deep JSON structural diff → `JsonPatch` |\r\n| `applyPatch(original, patch)` | Apply patch, returns new object (never mutates) |\r\n| `canApply(original, patch)` | Returns `true` if patch applies cleanly |\r\n| `applyPatchSafe(original, patch)` | Returns `{ ok, result }` or `{ ok, conflicts }` |\r\n| `renderTextDiff(diff)` | Convert `TextDiff` to `DiffLine[]` for rendering |\r\n| `summarizePatch(patch)` | Human-readable summary string |\r\n\r\n## License\r\n\r\nMIT © 2026 Gordon Schauer\r\n","readmeFilename":"README.md","_rev":"1-689f1d516379afbd56eac055b1f4ca9d"}