{"id":26487081,"url":"https://github.com/kieraneglin/ot-diff","last_synced_at":"2025-03-20T06:33:32.936Z","repository":{"id":57316720,"uuid":"92770983","full_name":"kieraneglin/ot-diff","owner":"kieraneglin","description":"Operational-transformation diffing tool for JavaScript","archived":false,"fork":false,"pushed_at":"2021-01-23T22:14:29.000Z","size":31,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T16:55:42.741Z","etag":null,"topics":["diffing","es2015","javascript","operational-transformations","ot"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kieraneglin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-29T19:56:01.000Z","updated_at":"2024-04-28T22:40:28.000Z","dependencies_parsed_at":"2022-08-25T20:40:43.942Z","dependency_job_id":null,"html_url":"https://github.com/kieraneglin/ot-diff","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kieraneglin%2Fot-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kieraneglin%2Fot-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kieraneglin%2Fot-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kieraneglin%2Fot-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kieraneglin","download_url":"https://codeload.github.com/kieraneglin/ot-diff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244566371,"owners_count":20473441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["diffing","es2015","javascript","operational-transformations","ot"],"created_at":"2025-03-20T06:33:26.651Z","updated_at":"2025-03-20T06:33:32.928Z","avatar_url":"https://github.com/kieraneglin.png","language":"JavaScript","readme":"# ot-diff\n\nA diffing tool for [operational-transformations](http://operational-transformation.github.io/what-is-ot.html) in JavaScript.\n\n(note: this is not a diffing tool as you might expect.  For git-style diffs, check out [diff](https://github.com/kpdecker/jsdiff))\n\n## Purpose\n\nWhen working with operational-transformations (OT), you need to know when a block of text is inserted, deleted, or replaced.  You're only working with contiguous changes in strings (contiguous meaning that all changes are together.  There's never more than one group of changes).\n\nHere's an example:\n\n```bash\n# contiguous changes (what OT handles)\nstring  -\u003e strings # insertion\nstrings -\u003e string # deletion\nstring  -\u003e strong # replacement\n\n# non-contiguous changes (what OT can't handle)\nstring  -\u003e things\n```\n\nThis library exists to give you OT-friendly diffs between two strings.\n\n## Usage\n\nInstall with\n\n```bash\nnpm install ot-diff --save\n# Or\nyarn add ot-diff\n```\n\nInclude with\n\n```javascript\nimport OtDiff from 'ot-diff';\n// Or\nconst OtDiff = require('ot-diff');\n```\n\nUse with\n\n```javascript\nOtDiff.diff('old string', 'new string', raw);\n// raw is an optional boolean that will give you more information about the diff.  Default: false\n```\n\n### Examples\n\nFor more examples, see `src/test/`.\n\n#### Insertion\n\n```javascript\nOtDiff.diff('strin', 'string')\n\n// returns:\n// {\n//   action: 'insert',\n//   payload: 'g',\n//   start: 5 \u003c- character which to insert after (0-indexed)\n// }\n```\n\n#### Deletion\n\n```javascript\nOtDiff.diff('string', 'strin')\n\n// returns:\n// {\n//   action: 'delete',\n//   start: 5, \u003c- character at which deletion starts (0-indexed)\n// Deletion includes this character.\n//   remove: 1 \u003c- number of characters removed\n// }\n```\n\n#### Replacement\n\n```javascript\n\nOtDiff.diff('string', 'strong')\n\n// returns:\n// {\n//   action: 'replace',\n//   start: 3,\n//   remove: 1,\n//   payload: 'o'\n// }\n```\n\n#### No changes\n\n```javascript\nOtDiff.diff('string', 'string')\n\n// returns:\n// {\n//   action: 'noop'\n// }\n```\n\n### Transform tools\n\nThere are four helper tools for applying transformations to a string.\n\nThey all take the string you're manipulating and the transform returned by `OtDiff.diff`.  They are:\n\n```javascript\nlet transform = OtDiff.diff(...);\n\nOtDiff.insert('string', transform);\nOtDiff.delete('string', transform);\nOtDiff.replace('string', transform);\nOtDiff.noop('string', transform);\n```\nOr, if you want the transform to be applied based on the value of `diff.action`, you can use this:\n\n```javascript\nlet transform = OtDiff.diff(...);\n\nOtDiff.transform('string', transform); // Automatically applies the correct transformation based on transform\n```\n\n## Contributing\n\n### Changing code\nEdit what you need in `src/ot-diff.js` then run `npm run compile` before submittig a PR.\n\nEnsure that all tests are passing and you add any appropriate new tests before submitting!\n\n### Running tests\n\n`npm run test` will compile and run the compiled tests.\n\n### Benchmarking\n\nPlease benchmark before and after contributing with `npm run benchmark`.  If your additions cause poor performance, they may be rejected.\n\n#### Other\n\nBug reports and pull requests are welcome on GitHub at https://github.com/kieraneglin/ot-diff/. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.\n\n## License\n\nThe package is available as open source under the terms of the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkieraneglin%2Fot-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkieraneglin%2Fot-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkieraneglin%2Fot-diff/lists"}