Line-level text diffing for Clojure, ClojureScript and babashka. Produces the same unified diff format as git diff and diff -u.
io.github.borkdude/text-diff {:mvn/version "0.1.0"}Or as a git dependency:
io.github.borkdude/text-diff {:git/sha "..."}(require '[borkdude.text-diff :as td])Returns a vector of tagged lines:
(td/diff "a\nb\nc" "a\nB\nc")
;; => [[:= "a"] [:- "b"] [:+ "B"] [:= "c"]]Produces unified diff output (diff -u format):
(println (td/unified-diff "a\nb\nc\nd" "a\nc\nd" {:filename "test.clj"}))--- a/test.clj
+++ b/test.clj
@@ -1,4 +1,3 @@
a
-b
c
d
Options:
:filename- filename for the header (default"a"):context- number of context lines (default3)
Adds ANSI color codes to unified diff text (cyan hunk headers, red deletions, green additions):
(println (td/colorize-unified-diff (td/unified-diff "a\nb\nc" "a\nB\nc" {:filename "test.clj"})))MIT, see LICENSE.