{"id":34595667,"url":"https://github.com/kushalshit27/diff-leven","last_synced_at":"2026-04-01T22:09:07.020Z","repository":{"id":295487640,"uuid":"979352130","full_name":"kushalshit27/diff-leven","owner":"kushalshit27","description":"Git like diff between two types, using the Levenshtein distance algorithm","archived":false,"fork":false,"pushed_at":"2026-03-10T12:08:32.000Z","size":157,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-10T17:36:03.107Z","etag":null,"topics":["compare","comparison-tool","diff","js-diff","levenshtein","levenshtein-distance"],"latest_commit_sha":null,"homepage":"https://kushalshit27.github.io/diff-leven/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kushalshit27.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-07T11:35:45.000Z","updated_at":"2026-03-10T12:05:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"68b2050b-a594-4f3e-b03d-aef64e69d06c","html_url":"https://github.com/kushalshit27/diff-leven","commit_stats":null,"previous_names":["kushalshit27/diff-leven"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/kushalshit27/diff-leven","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kushalshit27%2Fdiff-leven","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kushalshit27%2Fdiff-leven/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kushalshit27%2Fdiff-leven/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kushalshit27%2Fdiff-leven/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kushalshit27","download_url":"https://codeload.github.com/kushalshit27/diff-leven/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kushalshit27%2Fdiff-leven/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31018568,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T03:51:26.850Z","status":"ssl_error","status_checked_at":"2026-03-27T03:51:09.693Z","response_time":164,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compare","comparison-tool","diff","js-diff","levenshtein","levenshtein-distance"],"created_at":"2025-12-24T11:35:10.847Z","updated_at":"2026-03-27T04:23:47.530Z","avatar_url":"https://github.com/kushalshit27.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# diff-leven\n\n\u003e Git-like diff between two strings or objects, powered by the Levenshtein distance algorithm\n\n[![npm version](https://img.shields.io/npm/v/diff-leven)](https://www.npmjs.com/package/diff-leven)\n[![npm](https://img.shields.io/npm/dm/diff-leven.svg)](https://www.npmjs.com/package/diff-leven)\n[![jsdelivr](https://data.jsdelivr.com/v1/package/npm/diff-leven/badge?style=rounded)](https://www.jsdelivr.com/package/npm/diff-leven)\n![License](https://img.shields.io/npm/l/diff-leven.svg)\n[\u003cimg src=\"https://devin.ai/assets/deepwiki-badge.png\" alt=\"Ask questions about diff-leven on DeepWiki\" height=\"19\"/\u003e](https://deepwiki.com/kushalshit27/diff-leven)\n\n**Try now:** [link](https://kushalshit27.github.io/diff-leven/)\n\n---\n\n## ✨ Features\n\n- **Advanced Diff Generation**: Uses the Levenshtein distance algorithm for meaningful diffs\n- **Multiple Data Type Support**:\n  - Objects (including nested structures)\n  - Arrays (positional comparison; no reordering/LCS)\n  - Strings (character-level differences)\n  - Numbers, Booleans, and any serializable value\n- **Rich Output Options**:\n  - Git-style colorized output diff format with clear additions/removals\n\n- **Flexible Configuration**:\n  - `color`: Toggle color output (default: `true`)\n  - `keysOnly`: Compare only object structure/keys (default: `false`)\n  - `full`: Output the entire object tree, not just differences (default: `false`)\n  - `outputKeys`: Always include specified keys in output for objects with differences\n  - `ignoreKeys`: Skip specified keys when comparing objects\n  - `ignoreValues`: Ignore value differences, focus on structure\n\n---\n\n## 🚀 Quick Start\n\n### 1. Install\n\n```bash\nnpm install diff-leven\n```\n\n### 2. Usage\n\n```js\nconst { diff } = require('diff-leven');\n\nconsole.log(diff({ foo: 'bar' }, { foo: 'baz' }));\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//  }\n```\n\n---\n\n## 🛠️ API Reference\n\n### `diff(a, b, options?)`\n\nCompare two values (strings, objects, arrays, etc.) and return a formatted diff string.\n\n\u003e **Note on arrays:** comparison is positional only (index-by-index). Reordered elements are treated as removals/additions rather than matched by similarity.\n\n#### **Parameters**\n\n- `a`, `b`: Anything serializable (object, array, string, number, etc.)\n- `options` _(optional object)_:\n  - `color` _(boolean)_: Use colors in output (default: `true`)\n  - `keysOnly` _(boolean)_: Only compare object keys (default: `false`)\n  - `full` _(boolean)_: Output the entire JSON tree (default: `false`)\n  - `outputKeys` _(string[])_: Always include these keys in output (default: `[]`)\n  - `ignoreKeys` _(string[])_: Ignore these keys when comparing (default: `[]`)\n  - `ignoreValues` _(boolean)_: Ignore value differences (default: `false`)\n\n#### **Returns**\n\n- A string representing the diff between `a` and `b`.\n\n### `diffRaw(a, b, options?)`\n\nCompare two values (strings, objects, arrays, etc.) and return a structured diff result object.\n\n#### **Parameters**\n\n- `a`, `b`: Anything serializable (object, array, string, number, etc.)\n- `options` _(optional object)_:\n  - `color` _(boolean)_: Use colors in output (default: `true`)\n  - `keysOnly` _(boolean)_: Only compare object keys (default: `false`)\n  - `full` _(boolean)_: Output the entire JSON tree (default: `false`)\n  - `outputKeys` _(string[])_: Always include these keys in output (default: `[]`)\n  - `ignoreKeys` _(string[])_: Ignore these keys when comparing (default: `[]`)\n  - `ignoreValues` _(boolean)_: Ignore value differences (default: `false`)\n\n#### **Returns**\n\n- A structured object representing the diff between `a` and `b`.\n\n### `isDiff(a, b, options?)`\n\nCheck if two values (strings, objects, arrays, etc.) are different and return a boolean result.\n\n#### **Parameters**\n\n- `a`, `b`: Anything serializable (object, array, string, number, etc.)\n- `options` _(optional object)_:\n  - `keysOnly` _(boolean)_: Only compare object keys (default: `false`)\n  - `ignoreKeys` _(string[])_: Ignore these keys when comparing (default: `[]`)\n  - `ignoreValues` _(boolean)_: Ignore value differences (default: `false`)\n\n#### **Returns**\n\n- A boolean indicating if the values are different (`true` = different, `false` = identical).\n\n#### **Examples**\n\n```js\nconst { diff, diffRaw, isDiff } = require('diff-leven');\n\n// Basic diff (string output)\nconsole.log(diff({ foo: 'bar' }, { foo: 'baz' }));\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//  }\n\n// Raw diff object\nconst rawDiff = diffRaw({ foo: 'bar' }, { foo: 'baz' });\nconsole.log(JSON.stringify(rawDiff, null, 2));\n// Output:\n// {\n//   \"type\": \"changed\",\n//   \"path\": [],\n//   \"oldValue\": { \"foo\": \"bar\" },\n//   \"newValue\": { \"foo\": \"baz\" },\n//   \"children\": [\n//     {\n//       \"type\": \"changed\",\n//       \"path\": [\"foo\"],\n//       \"oldValue\": \"bar\",\n//       \"newValue\": \"baz\"\n//     }\n//   ]\n// }\n\n// Boolean diff check\nconsole.log(isDiff({ foo: 'bar' }, { foo: 'baz' }));\n// Output: true\n\nconsole.log(isDiff({ foo: 'bar' }, { foo: 'bar' }));\n// Output: false\n\n// With options\nconsole.log(\n  isDiff(\n    { foo: 'bar', timestamp: 123 },\n    { foo: 'bar', timestamp: 456 },\n    { ignoreKeys: ['timestamp'] },\n  ),\n);\n// Output: false (identical when ignoring timestamp)\n\n// No colors\nconsole.log(diff({ foo: 'bar' }, { foo: 'baz' }, { color: false }));\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//  }\n\n// Full output\nconsole.log(diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }, { full: true }));\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//    b: 3\n//  }\n\n// Ignore keys\nconsole.log(\n  diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }, { ignoreKeys: ['b'] }),\n);\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//  }\n\n// Ignore values\nconsole.log(\n  diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }, { ignoreValues: true }),\n);\n// Output showing structural differences only\n\n// Show similarity info for string changes\nconsole.log(\n  diff('hello world', 'hello there', { color: true, withSimilarity: true }),\n);\n// Output:\n// - 'hello world'\n// + 'hello there' (73% similar)\n\n// Output specific keys\nconsole.log(\n  diff({ foo: 'bar', b: 3 }, { foo: 'baz', b: 3 }, { outputKeys: ['foo'] }),\n);\n// Output:\n//  {\n// -  foo: \"bar\"\n// +  foo: \"baz\"\n//  }\n\n// Combine options\nconsole.log(\n  diff(\n    { foo: 'bar', b: 3 },\n    { foo: 'baz', b: 3 },\n    {\n      keysOnly: true,\n      ignoreKeys: ['b'],\n      ignoreValues: true,\n      outputKeys: ['foo'],\n      full: true,\n      color: false,\n    },\n  ),\n);\n```\n\n---\n\n## ⚙️ Options Matrix\n\n| Option           | Type     | Default | Description                                  |\n| ---------------- | -------- | ------- | -------------------------------------------- |\n| `color`          | boolean  | true    | Use colorized output                         |\n| `keysOnly`       | boolean  | false   | Only compare object keys                     |\n| `full`           | boolean  | false   | Output the entire object tree                |\n| `outputKeys`     | string[] | []      | Always include these keys in output          |\n| `ignoreKeys`     | string[] | []      | Ignore these keys when comparing             |\n| `ignoreValues`   | boolean  | false   | Ignore value differences, focus on structure |\n| `withSimilarity` | boolean  | false   | Show similarity info for string changes      |\n\n---\n\n## 📦 Examples\n\nSee [`examples/basic.js`](examples/basic.js) for more usage patterns.\n\n---\n\n## 🤝 Contributing\n\n1. Fork the repo\n2. Create your feature branch (`git checkout -b feature/YourFeature`)\n3. Commit your changes (`git commit -am 'Add new feature'`)\n4. Push to the branch (`git push origin feature/YourFeature`)\n5. Open a pull request\n\n---\n\n## 📄 License\n\nMIT © [kushalshit27](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkushalshit27%2Fdiff-leven","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkushalshit27%2Fdiff-leven","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkushalshit27%2Fdiff-leven/lists"}