github.com/dsisnero/similar.cr
main / published Feb 2, 2026 / repository
Crystal port of the similar diff library
similar
A Crystal port of the Rust similar diff library.
Installation
Add this to your application's shard.yml:
dependencies:
similar:
github: dsisnero/similar
Then run:
shards install
Usage
Basic text diff:
require "similar"
diff = Similar::TextDiff.from_lines("a\nb\n", "a\nB\n")
diff.iter_all_changes.each do |change|
puts "#{change.tag}: #{change.value}"
end
Unified diff:
require "similar"
old_text = "Hello\nWorld\n"
new_text = "Hello\nCrystal\n"
diff = Similar::TextDiff.from_lines(old_text, new_text)
puts diff.unified_diff.header("old.txt", "new.txt").to_s
Close matches:
require "similar"
matches = Similar.get_close_matches("appel", ["ape", "apple", "peach", "puppy"], 3, 0.6)
pp matches
Development
Run formatting, linting, and specs:
crystal tool format
ameba --fix
ameba
crystal spec
Contributing
- Fork it (https://github.com/dsisnero/similar/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- dsisnero - creator and maintainer