{"id":15010142,"url":"https://github.com/danilamihailov/differ","last_synced_at":"2025-04-09T18:07:12.022Z","repository":{"id":57489995,"uuid":"234890192","full_name":"DanilaMihailov/differ","owner":"DanilaMihailov","description":"Small library for creating diffs and applying them","archived":false,"fork":false,"pushed_at":"2020-05-14T04:55:51.000Z","size":169,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T20:04:11.833Z","etag":null,"topics":["diff","diffing","elixir","elixir-library"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanilaMihailov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-19T11:39:48.000Z","updated_at":"2024-07-24T04:03:14.000Z","dependencies_parsed_at":"2022-09-26T18:10:43.967Z","dependency_job_id":null,"html_url":"https://github.com/DanilaMihailov/differ","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanilaMihailov","download_url":"https://codeload.github.com/DanilaMihailov/differ/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085157,"owners_count":21045135,"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":["diff","diffing","elixir","elixir-library"],"created_at":"2024-09-24T19:30:45.167Z","updated_at":"2025-04-09T18:07:11.987Z","avatar_url":"https://github.com/DanilaMihailov.png","language":"Elixir","readme":"# Differ [![Hex Version](https://img.shields.io/hexpm/v/differ.svg)](https://hex.pm/packages/differ) [![docs](https://img.shields.io/badge/docs-hexpm-blue.svg)](https://hexdocs.pm/differ/) [![Coverage Status](https://coveralls.io/repos/github/DanilaMihailov/differ/badge.svg?branch=master)](https://coveralls.io/github/DanilaMihailov/differ?branch=master)\n\nSmall library for creating diffs and applying them\n\n```elixir\niex\u003e Differ.diff(\"Hello!\", \"Hey!\")\n[eq: \"He\", del: \"llo\", ins: \"y\", eq: \"!\"]\n\niex\u003e Differ.patch(\"Hello!\", [eq: \"He\", del: \"llo\", ins: \"y\", eq: \"!\"])\n{:ok, \"Hey!\"}\n```\n\n## Installation\n\nThe package can be installed\nby adding `differ` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:differ, \"~\u003e 0.1.1\"}\n  ]\nend\n```\n\n## Documentation\n\nDocumentation can be found at [https://hexdocs.pm/differ](https://hexdocs.pm/differ).\n\n## Usage\n\nSimple diff of two maps\n\n```elixir\niex\u003e user = %{name: \"John\"}\niex\u003e updated_user = Map.put(user, :age, 25)\niex\u003e Differ.diff(user, updated_user)\n[{:name, :eq, \"John\"}, {:age, :ins, 25}]\n```\n\nFor lists and strings using `List.myers_difference/3` and `String.myers_difference/2` respectevly.\nSo diffs of lists and strings a excactly output of this functions\n```elixir\niex\u003e Differ.diff(\"Hello!\", \"Hey!\")\n[eq: \"He\", del: \"llo\", ins: \"y\", eq: \"!\"]\n```\n\nIt is possible to use `Differ` with structs, you need to derive default implementation\nfor `Differ.Diffable` and `Differ.Patchable` protocols:\n```elixir\ndefmodule User do\n    @derive [Differ.Diffable, Differ.Patchable]\n    defstruct name: \"\", age: 21\nend\n```\nAnd now you can call `Differ.diff/2` with your structs:\n```elixir\niex\u003e Differ.diff(%User{name: \"John\"}, %User{name: \"John Smith\"})\n[{:name, :diff, [eq: \"John\", ins: \" Smith\"]}, {:age, :eq, 21}]\n```\n\nAs well as creating diffs, you can apply diff to a `term`. There is `Differ.patch/2` and `Differ.revert/2` for this purposes.\n\n```elixir\niex\u003e diff = Differ.diff(\"Hello!\", \"Hey!\")\niex\u003e Differ.patch(\"Hello!\", diff)\n{:ok, \"Hey!\"}\n```\nor revert diff\n```elixir\niex\u003e Differ.revert(\"Hey!\", diff)\n{:ok, \"Hello!\"}\n```\n\nFor more examples look at the [docs](https://hexdocs.pm/differ/Differ.html).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilamihailov%2Fdiffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanilamihailov%2Fdiffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilamihailov%2Fdiffer/lists"}